Files
Geoffroy BONNEVILLE f950564000 Update groups finally implemented
Code cleanup
2020-04-16 17:16:03 +02:00

34 lines
1.1 KiB
C#

using AutoMapper;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Entry.Commands.RestoreHistory
{
public class RestoreHistoryCommand : IRequest
{
public EntryVm Entry { get; set; }
public int HistoryIndex { get; set; }
public class RestoreHistoryCommandHandler : IRequestHandler<RestoreHistoryCommand>
{
private readonly IDatabaseProxy _database;
private readonly IMapper _mapper;
public RestoreHistoryCommandHandler(IDatabaseProxy database, IMapper mapper)
{
_database = database;
_mapper = mapper;
}
public void Handle(RestoreHistoryCommand message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
var entry = _database.RestoreFromHistory(message.Entry.Id, message.HistoryIndex);
message.Entry = _mapper.Map<EntryVm>(entry);
}
}
}
}