2020-03-26 12:25:22 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediatR;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Application.Entry.Models;
|
|
|
|
|
using ModernKeePass.Application.Group.Models;
|
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Application.Group.Commands.RemoveEntry
|
|
|
|
|
{
|
|
|
|
|
public class RemoveEntryCommand : IRequest
|
|
|
|
|
{
|
|
|
|
|
public GroupVm ParentGroup { get; set; }
|
|
|
|
|
public EntryVm Entry { get; set; }
|
2020-04-01 19:37:30 +02:00
|
|
|
|
public bool IsDelete { get; set; }
|
2020-03-26 12:25:22 +01:00
|
|
|
|
|
|
|
|
|
public class RemoveEntryCommandHandler : IAsyncRequestHandler<RemoveEntryCommand>
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public RemoveEntryCommandHandler(IDatabaseProxy database)
|
2020-03-26 12:25:22 +01:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Handle(RemoveEntryCommand 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-01 19:37:30 +02:00
|
|
|
|
await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id, message.IsDelete);
|
2020-03-26 12:25:22 +01:00
|
|
|
|
message.ParentGroup.Entries.Remove(message.Entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|