2020-03-26 12:25:22 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediatR;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Application.Group.Commands.AddGroup
|
|
|
|
|
{
|
|
|
|
|
public class AddGroupCommand : IRequest
|
|
|
|
|
{
|
2020-04-28 15:20:47 +02:00
|
|
|
|
public string ParentGroupId { get; set; }
|
|
|
|
|
public string GroupId { get; set; }
|
2020-03-26 12:25:22 +01:00
|
|
|
|
|
|
|
|
|
public class AddGroupCommandHandler : IAsyncRequestHandler<AddGroupCommand>
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public AddGroupCommandHandler(IDatabaseProxy database)
|
2020-03-26 12:25:22 +01:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Handle(AddGroupCommand 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-28 15:20:47 +02:00
|
|
|
|
await _database.AddGroup(message.ParentGroupId, message.GroupId);
|
2020-03-26 12:25:22 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|