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

@@ -1,27 +1,32 @@
using MediatR;
using AutoMapper;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Entry.Commands.AddHistory
{
public class AddHistoryCommand : IRequest
{
public string EntryId { get; set; }
public EntryVm Entry { get; set; }
public class AddHistoryCommandHandler : IRequestHandler<AddHistoryCommand>
{
private readonly IDatabaseProxy _database;
private readonly IMapper _mapper;
public AddHistoryCommandHandler(IDatabaseProxy database)
public AddHistoryCommandHandler(IDatabaseProxy database, IMapper mapper)
{
_database = database;
_mapper = mapper;
}
public void Handle(AddHistoryCommand message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
_database.AddHistory(message.EntryId);
var history = _database.AddHistory(message.Entry.Id);
message.Entry.History.Add(_mapper.Map<EntryVm>(history));
}
}
}