Update groups finally implemented

Code cleanup
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-16 17:16:03 +02:00
parent 9befdc321a
commit f950564000
15 changed files with 123 additions and 101 deletions

View File

@@ -0,0 +1,41 @@
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Group.Commands.UpdateGroup
{
public class UpdateGroupCommand : IRequest
{
public GroupVm Group { get; set; }
public string Title { get; set; }
public Icon Icon { get; set; }
public class UpdateGroupCommandHandler : IRequestHandler<UpdateGroupCommand>
{
private readonly IDatabaseProxy _database;
public UpdateGroupCommandHandler(IDatabaseProxy database)
{
_database = database;
}
public void Handle(UpdateGroupCommand message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
var group = new GroupEntity
{
Id = message.Group.Id,
Name = message.Title,
Icon = message.Icon
};
_database.UpdateGroup(group);
message.Group.Title = message.Title;
message.Group.Icon = message.Icon;
}
}
}
}