mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Handle entities with id
No hierarchy is built anymore WIP save issues after delete
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ namespace ModernKeePass.Application.Group.Models
|
||||
public class GroupVm: IEntityVm, ISelectableModel, IMapFrom<GroupEntity>
|
||||
{
|
||||
public string ParentGroupId { get; set; }
|
||||
public string ParentGroupName { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
@@ -29,12 +30,13 @@ namespace ModernKeePass.Application.Group.Models
|
||||
{
|
||||
profile.CreateMap<GroupEntity, GroupVm>()
|
||||
.ForMember(d => d.ParentGroupId, opts => opts.MapFrom(s => s.ParentId))
|
||||
.ForMember(d => d.ParentGroupName, opts => opts.MapFrom(s => s.ParentName))
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
|
||||
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Icon, opts => opts.MapFrom(s => s.Icon))
|
||||
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries))
|
||||
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.SubGroups))
|
||||
.MaxDepth(1);
|
||||
.MaxDepth(2);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user