2020-03-26 12:25:22 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediatR;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Application.Group.Models;
|
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Application.Group.Commands.RemoveGroup
|
|
|
|
|
{
|
|
|
|
|
public class RemoveGroupCommand : IRequest
|
|
|
|
|
{
|
|
|
|
|
public GroupVm ParentGroup { get; set; }
|
|
|
|
|
public GroupVm Group { get; set; }
|
|
|
|
|
|
|
|
|
|
public class RemoveGroupCommandHandler : IAsyncRequestHandler<RemoveGroupCommand>
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public RemoveGroupCommandHandler(IDatabaseProxy database)
|
2020-03-26 12:25:22 +01:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Handle(RemoveGroupCommand message)
|
|
|
|
|
{
|
2020-03-26 19:04:51 +01:00
|
|
|
|
if (!_database.IsOpen) throw new DatabaseClosedException();
|
2020-03-26 12:25:22 +01:00
|
|
|
|
|
2020-04-02 19:12:16 +02:00
|
|
|
|
await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id);
|
2020-03-26 12:25:22 +01:00
|
|
|
|
message.ParentGroup.SubGroups.Remove(message.Group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|