2020-03-27 13:27:29 +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;
|
|
|
|
|
|
2020-04-09 19:43:06 +02:00
|
|
|
|
namespace ModernKeePass.Application.Group.Commands.MoveEntry
|
2020-03-27 13:27:29 +01:00
|
|
|
|
{
|
2020-04-09 19:43:06 +02:00
|
|
|
|
public class MoveEntryCommand : IRequest
|
2020-03-27 13:27:29 +01:00
|
|
|
|
{
|
|
|
|
|
public GroupVm ParentGroup { get; set; }
|
|
|
|
|
public EntryVm Entry { get; set; }
|
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
|
2020-04-09 19:43:06 +02:00
|
|
|
|
public class MoveEntryCommandHandler : IAsyncRequestHandler<MoveEntryCommand>
|
2020-03-27 13:27:29 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
2020-04-09 19:43:06 +02:00
|
|
|
|
public MoveEntryCommandHandler(IDatabaseProxy database)
|
2020-03-27 13:27:29 +01:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 19:43:06 +02:00
|
|
|
|
public async Task Handle(MoveEntryCommand message)
|
2020-03-27 13:27:29 +01:00
|
|
|
|
{
|
|
|
|
|
if (!_database.IsOpen) throw new DatabaseClosedException();
|
|
|
|
|
|
2020-04-09 19:43:06 +02:00
|
|
|
|
await _database.MoveEntry(message.ParentGroup.Id, message.Entry.Id, message.Index);
|
2020-03-27 13:27:29 +01:00
|
|
|
|
message.ParentGroup.Entries.Insert(message.Index, message.Entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|