Handle entities with id

No hierarchy is built anymore
WIP save issues after delete
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-02 19:12:16 +02:00
parent b61a9652d1
commit 36aa8914fa
26 changed files with 213 additions and 96 deletions

View File

@@ -8,7 +8,7 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
{
public class CreateGroupCommand : IRequest<GroupVm>
{
public string ParentGroupId { get; set; }
public GroupVm ParentGroup { get; set; }
public string Name { get; set; }
public bool IsRecycleBin { get; set; }
@@ -27,8 +27,9 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
{
if (!_database.IsOpen) throw new DatabaseClosedException();
var group = _database.CreateGroup(message.ParentGroupId, message.Name, message.IsRecycleBin);
var group = _database.CreateGroup(message.ParentGroup.Id, message.Name, message.IsRecycleBin);
var groupVm = _mapper.Map<GroupVm>(group);
message.ParentGroup.SubGroups.Add(groupVm);
return groupVm;
}
}

View File

@@ -0,0 +1,31 @@
using System.Threading.Tasks;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Group.Commands.DeleteEntry
{
public class DeleteEntryCommand : IRequest
{
public string ParentGroupId { get; set; }
public string EntryId { get; set; }
public string RecycleBinName { get; set; }
public class DeleteEntryCommandHandler : IAsyncRequestHandler<DeleteEntryCommand>
{
private readonly IDatabaseProxy _database;
public DeleteEntryCommandHandler(IDatabaseProxy database)
{
_database = database;
}
public async Task Handle(DeleteEntryCommand message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
await _database.DeleteEntry(message.ParentGroupId, message.EntryId, message.RecycleBinName);
}
}
}
}

View File

@@ -0,0 +1,31 @@
using System.Threading.Tasks;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Group.Commands.DeleteGroup
{
public class DeleteGroupCommand : IRequest
{
public string ParentGroupId { get; set; }
public string GroupId { get; set; }
public string RecycleBinName { get; set; }
public class DeleteGroupCommandHandler : IAsyncRequestHandler<DeleteGroupCommand>
{
private readonly IDatabaseProxy _database;
public DeleteGroupCommandHandler(IDatabaseProxy database)
{
_database = database;
}
public async Task Handle(DeleteGroupCommand message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
await _database.DeleteEntry(message.ParentGroupId, message.GroupId, message.RecycleBinName);
}
}
}
}

View File

@@ -11,7 +11,6 @@ namespace ModernKeePass.Application.Group.Commands.RemoveEntry
{
public GroupVm ParentGroup { get; set; }
public EntryVm Entry { get; set; }
public bool IsDelete { get; set; }
public class RemoveEntryCommandHandler : IAsyncRequestHandler<RemoveEntryCommand>
{
@@ -26,7 +25,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveEntry
{
if (!_database.IsOpen) throw new DatabaseClosedException();
await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id, message.IsDelete);
await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id);
message.ParentGroup.Entries.Remove(message.Entry);
}
}

View File

@@ -10,7 +10,6 @@ namespace ModernKeePass.Application.Group.Commands.RemoveGroup
{
public GroupVm ParentGroup { get; set; }
public GroupVm Group { get; set; }
public bool IsDelete { get; set; }
public class RemoveGroupCommandHandler : IAsyncRequestHandler<RemoveGroupCommand>
{
@@ -25,7 +24,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveGroup
{
if (!_database.IsOpen) throw new DatabaseClosedException();
await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id, message.IsDelete);
await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id);
message.ParentGroup.SubGroups.Remove(message.Group);
}
}