mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Update groups finally implemented
Code cleanup
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,13 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Entry.Commands.DeleteHistory
|
||||
{
|
||||
public class DeleteHistoryCommand : IRequest
|
||||
{
|
||||
public string EntryId { get; set; }
|
||||
public EntryVm Entry { get; set; }
|
||||
public int HistoryIndex { get; set; }
|
||||
|
||||
public class DeleteHistoryCommandHandler : IRequestHandler<DeleteHistoryCommand>
|
||||
@@ -22,7 +23,8 @@ namespace ModernKeePass.Application.Entry.Commands.DeleteHistory
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
_database.DeleteHistory(message.EntryId, message.HistoryIndex);
|
||||
_database.DeleteHistory(message.Entry.Id, message.HistoryIndex);
|
||||
message.Entry.History.RemoveAt(message.HistoryIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,28 +1,33 @@
|
||||
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.RestoreHistory
|
||||
{
|
||||
public class RestoreHistoryCommand : IRequest
|
||||
{
|
||||
public string EntryId { get; set; }
|
||||
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)
|
||||
public RestoreHistoryCommandHandler(IDatabaseProxy database, IMapper mapper)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public void Handle(RestoreHistoryCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
_database.RestoreFromHistory(message.EntryId, message.HistoryIndex);
|
||||
var entry = _database.RestoreFromHistory(message.Entry.Id, message.HistoryIndex);
|
||||
message.Entry = _mapper.Map<EntryVm>(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user