Entry history delete and restore work

This commit is contained in:
Geoffroy BONNEVILLE
2020-04-16 14:08:50 +02:00
parent 98ac418f62
commit 9befdc321a
15 changed files with 196 additions and 96 deletions

View File

@@ -89,6 +89,7 @@
<Compile Include="Common\Mappings\IMapFrom.cs" />
<Compile Include="Common\Mappings\MappingProfile.cs" />
<Compile Include="Entry\Commands\AddHistory\AddHistoryCommand.cs" />
<Compile Include="Entry\Commands\DeleteHistory\DeleteHistoryCommand.cs" />
<Compile Include="Entry\Commands\RestoreHistory\RestoreHistoryCommand.cs" />
<Compile Include="Entry\Queries\GetEntry\GetEntryQuery.cs" />
<Compile Include="Group\Commands\DeleteEntry\DeleteEntryCommand.cs" />

View File

@@ -45,6 +45,7 @@ namespace ModernKeePass.Application.Common.Interfaces
void AddHistory(string entryId);
void RestoreFromHistory(string entryId, int historyIndex);
void DeleteHistory(string entryId, int historyIndex);
IEnumerable<EntryEntity> Search(string groupId, string text);
}

View File

@@ -0,0 +1,29 @@
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Entry.Commands.DeleteHistory
{
public class DeleteHistoryCommand : IRequest
{
public string EntryId { get; set; }
public int HistoryIndex { get; set; }
public class DeleteHistoryCommandHandler : IRequestHandler<DeleteHistoryCommand>
{
private readonly IDatabaseProxy _database;
public DeleteHistoryCommandHandler(IDatabaseProxy database)
{
_database = database;
}
public void Handle(DeleteHistoryCommand message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
_database.DeleteHistory(message.EntryId, message.HistoryIndex);
}
}
}
}

View File

@@ -28,7 +28,6 @@ namespace ModernKeePass.Application.Entry.Models
public bool HasExpirationDate { get; set; }
public DateTimeOffset ExpirationDate { get; set; }
public DateTimeOffset ModificationDate { get; set; }
public bool IsDirty { get; set; }
public override string ToString()
{
@@ -47,7 +46,7 @@ namespace ModernKeePass.Application.Entry.Models
.ForMember(d => d.Url, opts => opts.MapFrom(s => s.Url))
.ForMember(d => d.Notes, opts => opts.MapFrom(s => s.Notes))
.ForMember(d => d.AdditionalFields, opts => opts.MapFrom(s => s.AdditionalFields))
.ForMember(d => d.History, opts => opts.MapFrom(s => s.History.OrderByDescending(h => h.LastModificationDate)))
.ForMember(d => d.History, opts => opts.MapFrom(s => s.History.Reverse()))
.ForMember(d => d.HasExpirationDate, opts => opts.MapFrom(s => s.HasExpirationDate))
.ForMember(d => d.ExpirationDate, opts => opts.MapFrom(s => s.ExpirationDate))
.ForMember(d => d.ModificationDate, opts => opts.MapFrom(s => s.LastModificationDate))

View File

@@ -9,7 +9,7 @@ using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.Application.Group.Models
{
public class GroupVm: IEntityVm, ISelectableModel, IMapFrom<GroupEntity>
public class GroupVm: IEntityVm, IMapFrom<GroupEntity>
{
public string ParentGroupId { get; set; }
public string ParentGroupName { get; set; }
@@ -18,7 +18,6 @@ namespace ModernKeePass.Application.Group.Models
public Icon Icon { get; set; }
public List<GroupVm> SubGroups { get; set; }
public List<EntryVm> Entries { get; set; }
public bool IsSelected { get; set; }
public override string ToString()
{