2020-05-11 19:22:41 +02: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.MoveGroup
|
|
|
|
|
{
|
|
|
|
|
public class MoveGroupCommand : IRequest
|
|
|
|
|
{
|
|
|
|
|
public GroupVm ParentGroup { get; set; }
|
|
|
|
|
public GroupVm Group { get; set; }
|
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
|
|
|
|
|
public class MoveGroupCommandHandler : IAsyncRequestHandler<MoveGroupCommand>
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
|
|
|
|
public MoveGroupCommandHandler(IDatabaseProxy database)
|
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Handle(MoveGroupCommand message)
|
|
|
|
|
{
|
|
|
|
|
if (!_database.IsOpen) throw new DatabaseClosedException();
|
|
|
|
|
|
|
|
|
|
await _database.MoveGroup(message.ParentGroup.Id, message.Group.Id, message.Index);
|
2020-05-18 14:14:28 +02:00
|
|
|
|
message.ParentGroup.Groups.Insert(message.Index, message.Group);
|
2020-05-11 19:22:41 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|