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