2020-04-16 17:16:03 +02:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
using MediatR;
|
2020-04-14 19:59:19 +02:00
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
2020-04-16 17:16:03 +02:00
|
|
|
|
using ModernKeePass.Application.Entry.Models;
|
2020-04-14 19:59:19 +02:00
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Application.Entry.Commands.AddHistory
|
|
|
|
|
{
|
|
|
|
|
public class AddHistoryCommand : IRequest
|
|
|
|
|
{
|
2020-04-16 17:16:03 +02:00
|
|
|
|
public EntryVm Entry { get; set; }
|
2020-04-14 19:59:19 +02:00
|
|
|
|
|
|
|
|
|
public class AddHistoryCommandHandler : IRequestHandler<AddHistoryCommand>
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
2020-04-16 17:16:03 +02:00
|
|
|
|
private readonly IMapper _mapper;
|
2020-04-14 19:59:19 +02:00
|
|
|
|
|
2020-04-16 17:16:03 +02:00
|
|
|
|
public AddHistoryCommandHandler(IDatabaseProxy database, IMapper mapper)
|
2020-04-14 19:59:19 +02:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
2020-04-16 17:16:03 +02:00
|
|
|
|
_mapper = mapper;
|
2020-04-14 19:59:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(AddHistoryCommand message)
|
|
|
|
|
{
|
|
|
|
|
if (!_database.IsOpen) throw new DatabaseClosedException();
|
|
|
|
|
|
2020-04-16 17:16:03 +02:00
|
|
|
|
var history = _database.AddHistory(message.Entry.Id);
|
|
|
|
|
message.Entry.History.Add(_mapper.Map<EntryVm>(history));
|
2020-04-14 19:59:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|