diff --git a/ModernKeePass.Application/Application.csproj b/ModernKeePass.Application/Application.csproj
index a5bbcf3..5f85e51 100644
--- a/ModernKeePass.Application/Application.csproj
+++ b/ModernKeePass.Application/Application.csproj
@@ -52,6 +52,8 @@
+
+
diff --git a/ModernKeePass.Application/Common/Interfaces/IDatabaseProxy.cs b/ModernKeePass.Application/Common/Interfaces/IDatabaseProxy.cs
index 70db0db..bbbe5b1 100644
--- a/ModernKeePass.Application/Common/Interfaces/IDatabaseProxy.cs
+++ b/ModernKeePass.Application/Common/Interfaces/IDatabaseProxy.cs
@@ -30,8 +30,10 @@ namespace ModernKeePass.Application.Common.Interfaces
Task AddGroup(string parentGroupId, string groupId);
void UpdateEntry(string entryId, string fieldName, object fieldValue);
void UpdateGroup(string groupId);
- Task RemoveEntry(string parentGroupId, string entryId, bool isToBeDeleted);
- Task RemoveGroup(string parentGroupId, string groupId, bool isToBeDeleted);
+ Task RemoveEntry(string parentGroupId, string entryId);
+ Task RemoveGroup(string parentGroupId, string groupId);
+ Task DeleteEntry(string parentGroupId, string entryId, string recycleBinName);
+ Task DeleteGroup(string parentGroupId, string groupId, string recycleBinName);
EntryEntity CreateEntry(string parentGroupId);
GroupEntity CreateGroup(string parentGroupId, string nameId, bool isRecycleBin = false);
void SortEntries(string groupId);
diff --git a/ModernKeePass.Application/Common/Interfaces/IEntityVm.cs b/ModernKeePass.Application/Common/Interfaces/IEntityVm.cs
index 9a56b1b..42498eb 100644
--- a/ModernKeePass.Application/Common/Interfaces/IEntityVm.cs
+++ b/ModernKeePass.Application/Common/Interfaces/IEntityVm.cs
@@ -10,5 +10,6 @@ namespace ModernKeePass.Application.Common.Interfaces
Icon Icon { get; set; }
List Breadcrumb { get; }
string ParentGroupId { get; set; }
+ string ParentGroupName { get; set; }
}
}
\ No newline at end of file
diff --git a/ModernKeePass.Application/Entry/Models/EntryVm.cs b/ModernKeePass.Application/Entry/Models/EntryVm.cs
index eb85d60..760ad90 100644
--- a/ModernKeePass.Application/Entry/Models/EntryVm.cs
+++ b/ModernKeePass.Application/Entry/Models/EntryVm.cs
@@ -12,6 +12,7 @@ namespace ModernKeePass.Application.Entry.Models
public class EntryVm: IEntityVm, IMapFrom
{
public string ParentGroupId { get; set; }
+ public string ParentGroupName { get; set; }
public List Breadcrumb { get; } = new List();
public string Id { get; set; }
public string Title { get; set; }
@@ -37,6 +38,7 @@ namespace ModernKeePass.Application.Entry.Models
{
profile.CreateMap()
.ForMember(d => d.ParentGroupId, opts => opts.MapFrom(s => s.ParentId))
+ .ForMember(d => d.ParentGroupName, opts => opts.MapFrom(s => s.ParentName))
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
.ForMember(d => d.Username, opts => opts.MapFrom(s => s.UserName))
diff --git a/ModernKeePass.Application/Group/Commands/CreateGroup/CreateGroupCommand.cs b/ModernKeePass.Application/Group/Commands/CreateGroup/CreateGroupCommand.cs
index 2a4ba96..33536c1 100644
--- a/ModernKeePass.Application/Group/Commands/CreateGroup/CreateGroupCommand.cs
+++ b/ModernKeePass.Application/Group/Commands/CreateGroup/CreateGroupCommand.cs
@@ -8,7 +8,7 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
{
public class CreateGroupCommand : IRequest
{
- public string ParentGroupId { get; set; }
+ public GroupVm ParentGroup { get; set; }
public string Name { get; set; }
public bool IsRecycleBin { get; set; }
@@ -27,8 +27,9 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
{
if (!_database.IsOpen) throw new DatabaseClosedException();
- var group = _database.CreateGroup(message.ParentGroupId, message.Name, message.IsRecycleBin);
+ var group = _database.CreateGroup(message.ParentGroup.Id, message.Name, message.IsRecycleBin);
var groupVm = _mapper.Map(group);
+ message.ParentGroup.SubGroups.Add(groupVm);
return groupVm;
}
}
diff --git a/ModernKeePass.Application/Group/Commands/DeleteEntry/DeleteEntryCommand.cs b/ModernKeePass.Application/Group/Commands/DeleteEntry/DeleteEntryCommand.cs
new file mode 100644
index 0000000..9a6b00c
--- /dev/null
+++ b/ModernKeePass.Application/Group/Commands/DeleteEntry/DeleteEntryCommand.cs
@@ -0,0 +1,31 @@
+using System.Threading.Tasks;
+using MediatR;
+using ModernKeePass.Application.Common.Interfaces;
+using ModernKeePass.Domain.Exceptions;
+
+namespace ModernKeePass.Application.Group.Commands.DeleteEntry
+{
+ public class DeleteEntryCommand : IRequest
+ {
+ public string ParentGroupId { get; set; }
+ public string EntryId { get; set; }
+ public string RecycleBinName { get; set; }
+
+ public class DeleteEntryCommandHandler : IAsyncRequestHandler
+ {
+ private readonly IDatabaseProxy _database;
+
+ public DeleteEntryCommandHandler(IDatabaseProxy database)
+ {
+ _database = database;
+ }
+
+ public async Task Handle(DeleteEntryCommand message)
+ {
+ if (!_database.IsOpen) throw new DatabaseClosedException();
+
+ await _database.DeleteEntry(message.ParentGroupId, message.EntryId, message.RecycleBinName);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ModernKeePass.Application/Group/Commands/DeleteGroup/DeleteGroupCommand.cs b/ModernKeePass.Application/Group/Commands/DeleteGroup/DeleteGroupCommand.cs
new file mode 100644
index 0000000..cde3cf6
--- /dev/null
+++ b/ModernKeePass.Application/Group/Commands/DeleteGroup/DeleteGroupCommand.cs
@@ -0,0 +1,31 @@
+using System.Threading.Tasks;
+using MediatR;
+using ModernKeePass.Application.Common.Interfaces;
+using ModernKeePass.Domain.Exceptions;
+
+namespace ModernKeePass.Application.Group.Commands.DeleteGroup
+{
+ public class DeleteGroupCommand : IRequest
+ {
+ public string ParentGroupId { get; set; }
+ public string GroupId { get; set; }
+ public string RecycleBinName { get; set; }
+
+ public class DeleteGroupCommandHandler : IAsyncRequestHandler
+ {
+ private readonly IDatabaseProxy _database;
+
+ public DeleteGroupCommandHandler(IDatabaseProxy database)
+ {
+ _database = database;
+ }
+
+ public async Task Handle(DeleteGroupCommand message)
+ {
+ if (!_database.IsOpen) throw new DatabaseClosedException();
+
+ await _database.DeleteEntry(message.ParentGroupId, message.GroupId, message.RecycleBinName);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ModernKeePass.Application/Group/Commands/RemoveEntry/RemoveEntryCommand.cs b/ModernKeePass.Application/Group/Commands/RemoveEntry/RemoveEntryCommand.cs
index dd634b3..d097292 100644
--- a/ModernKeePass.Application/Group/Commands/RemoveEntry/RemoveEntryCommand.cs
+++ b/ModernKeePass.Application/Group/Commands/RemoveEntry/RemoveEntryCommand.cs
@@ -11,7 +11,6 @@ namespace ModernKeePass.Application.Group.Commands.RemoveEntry
{
public GroupVm ParentGroup { get; set; }
public EntryVm Entry { get; set; }
- public bool IsDelete { get; set; }
public class RemoveEntryCommandHandler : IAsyncRequestHandler
{
@@ -26,7 +25,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveEntry
{
if (!_database.IsOpen) throw new DatabaseClosedException();
- await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id, message.IsDelete);
+ await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id);
message.ParentGroup.Entries.Remove(message.Entry);
}
}
diff --git a/ModernKeePass.Application/Group/Commands/RemoveGroup/RemoveGroupCommand.cs b/ModernKeePass.Application/Group/Commands/RemoveGroup/RemoveGroupCommand.cs
index 0ce7509..7fe9230 100644
--- a/ModernKeePass.Application/Group/Commands/RemoveGroup/RemoveGroupCommand.cs
+++ b/ModernKeePass.Application/Group/Commands/RemoveGroup/RemoveGroupCommand.cs
@@ -10,7 +10,6 @@ namespace ModernKeePass.Application.Group.Commands.RemoveGroup
{
public GroupVm ParentGroup { get; set; }
public GroupVm Group { get; set; }
- public bool IsDelete { get; set; }
public class RemoveGroupCommandHandler : IAsyncRequestHandler
{
@@ -25,7 +24,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveGroup
{
if (!_database.IsOpen) throw new DatabaseClosedException();
- await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id, message.IsDelete);
+ await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id);
message.ParentGroup.SubGroups.Remove(message.Group);
}
}
diff --git a/ModernKeePass.Application/Group/Models/GroupVm.cs b/ModernKeePass.Application/Group/Models/GroupVm.cs
index 2bb8d09..81d8f81 100644
--- a/ModernKeePass.Application/Group/Models/GroupVm.cs
+++ b/ModernKeePass.Application/Group/Models/GroupVm.cs
@@ -12,6 +12,7 @@ namespace ModernKeePass.Application.Group.Models
public class GroupVm: IEntityVm, ISelectableModel, IMapFrom
{
public string ParentGroupId { get; set; }
+ public string ParentGroupName { get; set; }
public string Id { get; set; }
public string Title { get; set; }
public Icon Icon { get; set; }
@@ -29,12 +30,13 @@ namespace ModernKeePass.Application.Group.Models
{
profile.CreateMap()
.ForMember(d => d.ParentGroupId, opts => opts.MapFrom(s => s.ParentId))
+ .ForMember(d => d.ParentGroupName, opts => opts.MapFrom(s => s.ParentName))
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
.ForMember(d => d.Icon, opts => opts.MapFrom(s => s.Icon))
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries))
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.SubGroups))
- .MaxDepth(1);
+ .MaxDepth(2);
}
}
}
\ No newline at end of file
diff --git a/ModernKeePass.Domain/Entities/BaseEntity.cs b/ModernKeePass.Domain/Entities/BaseEntity.cs
index 0c1586e..c734f1a 100644
--- a/ModernKeePass.Domain/Entities/BaseEntity.cs
+++ b/ModernKeePass.Domain/Entities/BaseEntity.cs
@@ -7,6 +7,7 @@ namespace ModernKeePass.Domain.Entities
public string Id { get; set; }
public string Name { get; set; }
public string ParentId { get; set; }
+ public string ParentName { get; set; }
public DateTimeOffset LastModificationDate { get; set; }
}
}
\ No newline at end of file
diff --git a/ModernKeePass.Infrastructure/KeePass/EntryMappingProfile.cs b/ModernKeePass.Infrastructure/KeePass/EntryMappingProfile.cs
index 3095508..c79015d 100644
--- a/ModernKeePass.Infrastructure/KeePass/EntryMappingProfile.cs
+++ b/ModernKeePass.Infrastructure/KeePass/EntryMappingProfile.cs
@@ -20,6 +20,7 @@ namespace ModernKeePass.Infrastructure.KeePass
Uri url;
CreateMap()
.ForMember(dest => dest.ParentId, opt => opt.MapFrom(src => src.ParentGroup.Uuid.ToHexString()))
+ .ForMember(dest => dest.ParentName, opt => opt.MapFrom(src => src.ParentGroup.Name))
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Uuid.ToHexString()))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.TitleField)))
.ForMember(dest => dest.UserName, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.UserNameField)))
@@ -39,9 +40,7 @@ namespace ModernKeePass.Infrastructure.KeePass
.ForMember(dest => dest.AdditionalFields, opt => opt.MapFrom(src =>
src.Strings.Where(s => !PwDefs.GetStandardFields().Contains(s.Key))
.ToDictionary(s => s.Key, s => GetEntryValue(src, s.Key))))
- .ForMember(dest => dest.LastModificationDate,
- opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime)))
- .MaxDepth(1);
+ .ForMember(dest => dest.LastModificationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime)));
}
private void FromModelToDto()
diff --git a/ModernKeePass.Infrastructure/KeePass/GroupMappingProfile.cs b/ModernKeePass.Infrastructure/KeePass/GroupMappingProfile.cs
index ffd8482..c572985 100644
--- a/ModernKeePass.Infrastructure/KeePass/GroupMappingProfile.cs
+++ b/ModernKeePass.Infrastructure/KeePass/GroupMappingProfile.cs
@@ -16,13 +16,14 @@ namespace ModernKeePass.Infrastructure.KeePass
{
CreateMap()
.ForMember(d => d.ParentId, opts => opts.MapFrom(s => s.ParentGroup.Uuid.ToHexString()))
+ .ForMember(d => d.ParentName, opts => opts.MapFrom(s => s.ParentGroup.Name))
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Uuid.ToHexString()))
.ForMember(d => d.Name, opts => opts.MapFrom(s => s.Name))
.ForMember(d => d.Icon, opts => opts.MapFrom(s => IconMapper.MapPwIconToIcon(s.IconId)))
.ForMember(d => d.LastModificationDate, opts => opts.MapFrom(s => s.LastModificationTime))
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries))
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.Groups))
- .MaxDepth(1);
+ .MaxDepth(2);
}
private void FromModelToDto()
diff --git a/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs b/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs
index e862eab..e3f06fc 100644
--- a/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs
+++ b/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs
@@ -194,36 +194,64 @@ namespace ModernKeePass.Infrastructure.KeePass
parentPwGroup.Groups.Add(pwGroup);
});
}
- public async Task RemoveEntry(string parentGroupId, string entryId, bool isToBeDeleted)
+ public async Task RemoveEntry(string parentGroupId, string entryId)
{
await Task.Run(() =>
{
var parentPwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(parentGroupId), true);
var pwEntry = parentPwGroup.FindEntry(BuildIdFromString(entryId), false);
parentPwGroup.Entries.Remove(pwEntry);
-
- if (isToBeDeleted && (!_pwDatabase.RecycleBinEnabled || parentPwGroup.Uuid.Equals(_pwDatabase.RecycleBinUuid)))
- {
- _pwDatabase.DeletedObjects.Add(new PwDeletedObject(pwEntry.Uuid, _dateTime.Now));
- }
});
}
- public async Task RemoveGroup(string parentGroupId, string groupId, bool isToBeDeleted)
+ public async Task RemoveGroup(string parentGroupId, string groupId)
{
await Task.Run(() =>
{
var parentPwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(parentGroupId), true);
var pwGroup = parentPwGroup.FindGroup(BuildIdFromString(groupId), false);
parentPwGroup.Groups.Remove(pwGroup);
-
- if (isToBeDeleted && (!_pwDatabase.RecycleBinEnabled || parentPwGroup.Uuid.Equals(_pwDatabase.RecycleBinUuid)))
- {
- _pwDatabase.DeletedObjects.Add(new PwDeletedObject(pwGroup.Uuid, _dateTime.Now));
- }
});
}
+ public async Task DeleteEntry(string parentGroupId, string entryId, string recycleBinName)
+ {
+ if (IsRecycleBinEnabled && (string.IsNullOrEmpty(RecycleBinId) || _pwDatabase.RecycleBinUuid.Equals(PwUuid.Zero)))
+ {
+ CreateGroup(RootGroupId, recycleBinName, true);
+ }
+
+ if (!IsRecycleBinEnabled || parentGroupId.Equals(RecycleBinId))
+ {
+ _pwDatabase.DeletedObjects.Add(new PwDeletedObject(BuildIdFromString(entryId), _dateTime.Now));
+ }
+ else
+ {
+ await AddEntry(RecycleBinId, entryId);
+ }
+
+ await RemoveEntry(parentGroupId, entryId);
+ }
+
+ public async Task DeleteGroup(string parentGroupId, string groupId, string recycleBinName)
+ {
+ if (IsRecycleBinEnabled && (string.IsNullOrEmpty(RecycleBinId) || _pwDatabase.RecycleBinUuid.Equals(PwUuid.Zero)))
+ {
+ CreateGroup(RootGroupId, recycleBinName, true);
+ }
+
+ if (!IsRecycleBinEnabled || parentGroupId.Equals(RecycleBinId))
+ {
+ _pwDatabase.DeletedObjects.Add(new PwDeletedObject(BuildIdFromString(groupId), _dateTime.Now));
+ }
+ else
+ {
+ await AddEntry(RecycleBinId, groupId);
+ }
+
+ await RemoveGroup(parentGroupId, groupId);
+ }
+
public void UpdateEntry(string entryId, string fieldName, object fieldValue)
{
var pwEntry = _pwDatabase.RootGroup.FindEntry(BuildIdFromString(entryId), true);
diff --git a/ModernKeePass/App.xaml.cs b/ModernKeePass/App.xaml.cs
index e3b95bb..5956fb2 100644
--- a/ModernKeePass/App.xaml.cs
+++ b/ModernKeePass/App.xaml.cs
@@ -167,9 +167,9 @@ namespace ModernKeePass
try
{
- var database = await Mediator.Send(new ReOpenDatabaseQuery());
+ await Mediator.Send(new ReOpenDatabaseQuery());
#if DEBUG
- ToastNotificationHelper.ShowGenericToast(database.Title, "Database reopened (changes were saved)");
+ ToastNotificationHelper.ShowGenericToast("App resumed", "Database reopened (changes were saved)");
#endif
}
catch (Exception)
diff --git a/ModernKeePass/Events/PasswordEventArgs.cs b/ModernKeePass/Events/PasswordEventArgs.cs
index 4311503..c19a6b9 100644
--- a/ModernKeePass/Events/PasswordEventArgs.cs
+++ b/ModernKeePass/Events/PasswordEventArgs.cs
@@ -1,15 +1,14 @@
using System;
-using ModernKeePass.Application.Group.Models;
namespace ModernKeePass.Events
{
public class PasswordEventArgs: EventArgs
{
- public GroupVm RootGroup { get; set; }
+ public string RootGroupId { get; set; }
- public PasswordEventArgs(GroupVm groupVm)
+ public PasswordEventArgs(string groupId)
{
- RootGroup = groupVm;
+ RootGroupId = groupId;
}
}
}
\ No newline at end of file
diff --git a/ModernKeePass/ViewModels/CompositeKeyVm.cs b/ModernKeePass/ViewModels/CompositeKeyVm.cs
index 2c01870..fb03ba9 100644
--- a/ModernKeePass/ViewModels/CompositeKeyVm.cs
+++ b/ModernKeePass/ViewModels/CompositeKeyVm.cs
@@ -5,6 +5,7 @@ using Windows.Storage;
using Windows.Storage.AccessCache;
using MediatR;
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
+using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Database.Queries.OpenDatabase;
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
@@ -97,7 +98,7 @@ namespace ModernKeePass.ViewModels
set { SetProperty(ref _keyFileText, value); }
}
- public Application.Group.Models.GroupVm RootGroup { get; set; }
+ public string RootGroupId { get; set; }
public double PasswordComplexityIndicator => _mediator.Send(new EstimatePasswordComplexityQuery { Password = Password }).GetAwaiter().GetResult();
@@ -129,11 +130,12 @@ namespace ModernKeePass.ViewModels
_isOpening = true;
OnPropertyChanged(nameof(IsValid));
- RootGroup = await _mediator.Send(new OpenDatabaseQuery {
+ await _mediator.Send(new OpenDatabaseQuery {
FilePath = StorageApplicationPermissions.FutureAccessList.Add(databaseFile),
KeyFilePath = HasKeyFile && KeyFile != null ? StorageApplicationPermissions.FutureAccessList.Add(KeyFile) : null,
Password = Password = HasPassword ? Password : null,
});
+ RootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
return true;
}
catch (ArgumentException)
diff --git a/ModernKeePass/ViewModels/EntryDetailVm.cs b/ModernKeePass/ViewModels/EntryDetailVm.cs
index 4af82d4..6a0e28a 100644
--- a/ModernKeePass/ViewModels/EntryDetailVm.cs
+++ b/ModernKeePass/ViewModels/EntryDetailVm.cs
@@ -9,15 +9,19 @@ using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Models;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Entry.Commands.SetFieldValue;
+using ModernKeePass.Application.Entry.Models;
+using ModernKeePass.Application.Entry.Queries.GetEntry;
using ModernKeePass.Application.Group.Commands.AddEntry;
-using ModernKeePass.Application.Group.Commands.CreateGroup;
+using ModernKeePass.Application.Group.Commands.DeleteEntry;
using ModernKeePass.Application.Group.Commands.RemoveEntry;
+using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Application.Security.Commands.GeneratePassword;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Common;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
+using ModernKeePass.Application.Group.Models;
namespace ModernKeePass.ViewModels
{
@@ -37,7 +41,7 @@ namespace ModernKeePass.ViewModels
public string CustomChars { get; set; } = string.Empty;
public string Id => _entry.Id;
- public IEnumerable BreadCrumb => _entry.Breadcrumb;
+ public IEnumerable BreadCrumb => new List { _parent };
///
/// Determines if the Entry is current or from history
@@ -174,7 +178,7 @@ namespace ModernKeePass.ViewModels
}
}
}
- public IEnumerable History => _entry.History;
+ public IEnumerable History => _entry.History;
public bool IsEditMode
{
@@ -206,13 +210,14 @@ namespace ModernKeePass.ViewModels
}
}
- public bool CanRestore => _entry.ParentGroup == _database.RecycleBin;
+ public bool CanRestore => _entry.ParentGroupId == _database.RecycleBinId;
public ICommand SaveCommand { get; }
public ICommand GeneratePasswordCommand { get; }
public ICommand UndoDeleteCommand { get; }
- private readonly Application.Entry.Models.EntryVm _entry;
+ private readonly EntryVm _entry;
+ private readonly GroupVm _parent;
private readonly IMediator _mediator;
private readonly DatabaseVm _database;
private bool _isEditMode;
@@ -222,19 +227,20 @@ namespace ModernKeePass.ViewModels
public EntryDetailVm() { }
- internal EntryDetailVm(Application.Entry.Models.EntryVm entry, bool isNewEntry = false) : this(entry, App.Mediator, isNewEntry) { }
+ internal EntryDetailVm(string entryId, bool isNewEntry = false) : this(entryId, App.Mediator, isNewEntry) { }
- public EntryDetailVm(Application.Entry.Models.EntryVm entry, IMediator mediator, bool isNewEntry = false)
+ public EntryDetailVm(string entryId, IMediator mediator, bool isNewEntry = false)
{
- _entry = entry;
_mediator = mediator;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
+ _entry = _mediator.Send(new GetEntryQuery {Id = entryId}).GetAwaiter().GetResult();
+ _parent = _mediator.Send(new GetGroupQuery {Id = _entry.ParentGroupId}).GetAwaiter().GetResult();
_isEditMode = isNewEntry;
if (isNewEntry) GeneratePassword().GetAwaiter().GetResult();
SaveCommand = new RelayCommand(() => _mediator.Send(new SaveDatabaseCommand()));
GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword());
- UndoDeleteCommand = new RelayCommand(async () => await Move(entry.ParentGroup), () => _entry.ParentGroup != null);
+ UndoDeleteCommand = new RelayCommand(async () => await Move(_parent), () => _parent != null);
}
public async Task GeneratePassword()
@@ -257,18 +263,16 @@ namespace ModernKeePass.ViewModels
public async Task MarkForDelete(string recycleBinTitle)
{
- if (_database.IsRecycleBinEnabled && _database.RecycleBin == null)
- _database.RecycleBin = await _mediator.Send(new CreateGroupCommand { ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
- await Move(_database.IsRecycleBinEnabled && _entry.ParentGroup != _database.RecycleBin ? _database.RecycleBin : null);
+ await _mediator.Send(new DeleteEntryCommand {EntryId = _entry.Id, ParentGroupId = _entry.ParentGroupId, RecycleBinName = recycleBinTitle});
}
- public async Task Move(Application.Group.Models.GroupVm destination)
+ public async Task Move(GroupVm destination)
{
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
- await _mediator.Send(new RemoveEntryCommand { ParentGroup = _entry.ParentGroup, Entry = _entry, IsDelete = true });
+ await _mediator.Send(new RemoveEntryCommand { ParentGroup = _parent, Entry = _entry });
}
- public Application.Entry.Models.EntryVm GetEntry()
+ public EntryVm GetEntry()
{
return _entry;
}
diff --git a/ModernKeePass/ViewModels/GroupDetailVm.cs b/ModernKeePass/ViewModels/GroupDetailVm.cs
index 54df627..33a98eb 100644
--- a/ModernKeePass/ViewModels/GroupDetailVm.cs
+++ b/ModernKeePass/ViewModels/GroupDetailVm.cs
@@ -9,15 +9,19 @@ using MediatR;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Models;
using ModernKeePass.Application.Database.Queries.GetDatabase;
+using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Application.Group.Commands.AddEntry;
using ModernKeePass.Application.Group.Commands.AddGroup;
using ModernKeePass.Application.Group.Commands.CreateEntry;
using ModernKeePass.Application.Group.Commands.CreateGroup;
+using ModernKeePass.Application.Group.Commands.DeleteGroup;
using ModernKeePass.Application.Group.Commands.InsertEntry;
using ModernKeePass.Application.Group.Commands.RemoveEntry;
using ModernKeePass.Application.Group.Commands.RemoveGroup;
using ModernKeePass.Application.Group.Commands.SortEntries;
using ModernKeePass.Application.Group.Commands.SortGroups;
+using ModernKeePass.Application.Group.Models;
+using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Common;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces;
@@ -27,15 +31,15 @@ namespace ModernKeePass.ViewModels
{
public class GroupDetailVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
{
- public ObservableCollection Entries => new ObservableCollection(_group.Entries);
+ public ObservableCollection Entries => new ObservableCollection(_group.Entries);
- public ObservableCollection Groups => new ObservableCollection(_group.SubGroups);
+ public ObservableCollection Groups => new ObservableCollection(_group.SubGroups);
- public IEnumerable SubEntries
+ public IEnumerable SubEntries
{
get
{
- var subEntries = new List();
+ var subEntries = new List();
subEntries.AddRange(Entries);
foreach (var group in Groups)
{
@@ -46,9 +50,9 @@ namespace ModernKeePass.ViewModels
}
}
- public bool IsNotRoot => _database.RootGroup != _group;
+ public bool IsNotRoot => _database.RootGroupId != _group.Id;
- public bool ShowRestore => IsNotRoot && _database.RecycleBin != _group;
+ public bool ShowRestore => IsNotRoot && _database.RecycleBinId != _group.Id;
///
/// Is the Group the database Recycle Bin?
@@ -57,15 +61,15 @@ namespace ModernKeePass.ViewModels
{
get
{
- return _database.IsRecycleBinEnabled && _database.RecycleBin == _group;
+ return _database.IsRecycleBinEnabled && _database.RecycleBinId == _group.Id;
}
set
{
- if (value && _group != null) _database.RecycleBin = _group;
+ if (value && _group != null) _database.RecycleBinId = _group.Id;
}
}
- public IOrderedEnumerable> EntriesZoomedOut => from e in Entries
+ public IOrderedEnumerable> EntriesZoomedOut => from e in Entries
group e by e.Title.ToUpper().FirstOrDefault() into grp
orderby grp.Key
select grp;
@@ -101,30 +105,36 @@ namespace ModernKeePass.ViewModels
set { SetProperty(ref _isMenuClosed, value); }
}
- public IEnumerable BreadCrumb => _group.Breadcrumb;
+ public IEnumerable BreadCrumb { get; }
public ICommand SaveCommand { get; }
public ICommand SortEntriesCommand { get; }
public ICommand SortGroupsCommand { get; }
public ICommand UndoDeleteCommand { get; }
- private readonly Application.Group.Models.GroupVm _group;
private readonly IMediator _mediator;
private readonly DatabaseVm _database;
+ private readonly GroupVm _group;
+ private readonly GroupVm _parent;
private bool _isEditMode;
- private Application.Entry.Models.EntryVm _reorderedEntry;
+ private EntryVm _reorderedEntry;
private bool _isMenuClosed = true;
public GroupDetailVm() {}
- internal GroupDetailVm(Application.Group.Models.GroupVm group) : this(group, App.Mediator)
+ internal GroupDetailVm(string groupId) : this(groupId, App.Mediator)
{ }
- public GroupDetailVm(Application.Group.Models.GroupVm group, IMediator mediator, bool isEditMode = false)
+ public GroupDetailVm(string groupId, IMediator mediator, bool isEditMode = false)
{
- _group = group;
_mediator = mediator;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
+ _group = _mediator.Send(new GetGroupQuery { Id = groupId }).GetAwaiter().GetResult();
+ if (!string.IsNullOrEmpty(_group.ParentGroupId))
+ {
+ _parent = _mediator.Send(new GetGroupQuery { Id = _group.ParentGroupId }).GetAwaiter().GetResult();
+ BreadCrumb = new List {_parent};
+ }
_isEditMode = isEditMode;
SaveCommand = new RelayCommand(async () => await _mediator.Send(new SaveDatabaseCommand()));
@@ -132,7 +142,7 @@ namespace ModernKeePass.ViewModels
await SortEntriesAsync().ConfigureAwait(false), () => IsEditMode);
SortGroupsCommand = new RelayCommand(async () =>
await SortGroupsAsync().ConfigureAwait(false), () => IsEditMode);
- UndoDeleteCommand = new RelayCommand(async () => await Move(group.ParentGroup), () => _group.ParentGroup != null);
+ UndoDeleteCommand = new RelayCommand(async () => await Move(_parent), () => _parent != null);
Entries.CollectionChanged += Entries_CollectionChanged;
}
@@ -160,28 +170,27 @@ namespace ModernKeePass.ViewModels
}
}
- public async Task AddNewGroup(string name = "")
+ public async Task AddNewGroup(string name = "")
{
- return await _mediator.Send(new CreateGroupCommand {Name = name, ParentGroup = _group});
+ return (await _mediator.Send(new CreateGroupCommand {Name = name, ParentGroup = _group})).Id;
}
- public async Task AddNewEntry()
+ public async Task AddNewEntry()
{
- return await _mediator.Send(new CreateEntryCommand { ParentGroup = _group });
+ return (await _mediator.Send(new CreateEntryCommand { ParentGroup = _group })).Id;
}
public async Task MarkForDelete(string recycleBinTitle)
{
- if (_database.IsRecycleBinEnabled && _database.RecycleBin == null)
- _database.RecycleBin = await _mediator.Send(new CreateGroupCommand {ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
- await Move(_database.IsRecycleBinEnabled && !IsSelected ? _database.RecycleBin : null);
+ await _mediator.Send(new DeleteGroupCommand { GroupId = _group.Id, ParentGroupId = _group.ParentGroupId, RecycleBinName = recycleBinTitle });
+
((RelayCommand)UndoDeleteCommand).RaiseCanExecuteChanged();
}
- public async Task Move(Application.Group.Models.GroupVm destination)
+ public async Task Move(GroupVm destination)
{
- await _mediator.Send(new AddGroupCommand {ParentGroup = destination, Group = _group});
- await _mediator.Send(new RemoveGroupCommand {ParentGroup = _group.ParentGroup, Group = _group, IsDelete = true });
+ await _mediator.Send(new AddGroupCommand {ParentGroup = destination, Group = _group });
+ await _mediator.Send(new RemoveGroupCommand {ParentGroup = _parent, Group = _group });
}
private async Task SortEntriesAsync()
diff --git a/ModernKeePass/ViewModels/Items/SettingsDatabaseVm.cs b/ModernKeePass/ViewModels/Items/SettingsDatabaseVm.cs
index 156b6ee..767dcf2 100644
--- a/ModernKeePass/ViewModels/Items/SettingsDatabaseVm.cs
+++ b/ModernKeePass/ViewModels/Items/SettingsDatabaseVm.cs
@@ -4,6 +4,8 @@ using System.Linq;
using MediatR;
using ModernKeePass.Application.Database.Models;
using ModernKeePass.Application.Database.Queries.GetDatabase;
+using ModernKeePass.Application.Group.Models;
+using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Application.Parameters.Commands.SetCipher;
using ModernKeePass.Application.Parameters.Commands.SetCompression;
using ModernKeePass.Application.Parameters.Commands.SetHasRecycleBin;
@@ -37,14 +39,14 @@ namespace ModernKeePass.ViewModels
public bool IsNewRecycleBin
{
- get { return _database.RecycleBin == null; }
+ get { return string.IsNullOrEmpty(_database.RecycleBinId); }
set
{
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBin = null }).Wait();
}
}
- public ObservableCollection Groups { get; set; }
+ public ObservableCollection Groups { get; set; }
public IEnumerable Ciphers => _mediator.Send(new GetCiphersQuery()).GetAwaiter().GetResult();
public IEnumerable Compressions => _mediator.Send(new GetCompressionsQuery()).GetAwaiter().GetResult();
@@ -119,7 +121,8 @@ namespace ModernKeePass.ViewModels
{
_mediator = mediator;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
- Groups = new ObservableCollection(_database.RootGroup.SubGroups);
+ var rootGroup = _mediator.Send(new GetGroupQuery { Id = _database.RootGroupId }).GetAwaiter().GetResult();
+ Groups = new ObservableCollection(rootGroup.SubGroups);
}
}
}
diff --git a/ModernKeePass/ViewModels/MainVm.cs b/ModernKeePass/ViewModels/MainVm.cs
index 959d6e5..e3d2ce1 100644
--- a/ModernKeePass/ViewModels/MainVm.cs
+++ b/ModernKeePass/ViewModels/MainVm.cs
@@ -127,7 +127,7 @@ namespace ModernKeePass.ViewModels
Title = database.Name,
PageType = typeof(GroupDetailPage),
Destination = referenceFrame,
- Parameter = database.RootGroup,
+ Parameter = database.RootGroupId,
Group = "Databases",
SymbolIcon = Symbol.ProtectedDocument
});
diff --git a/ModernKeePass/ViewModels/NewVm.cs b/ModernKeePass/ViewModels/NewVm.cs
index 1543bfa..8b20fa0 100644
--- a/ModernKeePass/ViewModels/NewVm.cs
+++ b/ModernKeePass/ViewModels/NewVm.cs
@@ -5,6 +5,8 @@ using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Entry.Commands.SetFieldValue;
using ModernKeePass.Application.Group.Commands.CreateEntry;
using ModernKeePass.Application.Group.Commands.CreateGroup;
+using ModernKeePass.Application.Group.Models;
+using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
@@ -44,14 +46,15 @@ namespace ModernKeePass.ViewModels
_settings = settings;
}
- public async Task PopulateInitialData()
+ public async Task PopulateInitialData()
{
var database = await _mediator.Send(new GetDatabaseQuery());
- if (_settings.GetSetting("Sample") && !IsImportChecked) await CreateSampleData(database.RootGroup);
- return database.RootGroup;
+ var rootGroup = await _mediator.Send(new GetGroupQuery {Id = database.RootGroupId});
+ if (_settings.GetSetting("Sample") && !IsImportChecked) await CreateSampleData(rootGroup);
+ return rootGroup;
}
- private async Task CreateSampleData(Application.Group.Models.GroupVm group)
+ private async Task CreateSampleData(GroupVm group)
{
/*var converter = new IntToSymbolConverter();
diff --git a/ModernKeePass/Views/EntryDetailPage.xaml.cs b/ModernKeePass/Views/EntryDetailPage.xaml.cs
index a168197..596cf76 100644
--- a/ModernKeePass/Views/EntryDetailPage.xaml.cs
+++ b/ModernKeePass/Views/EntryDetailPage.xaml.cs
@@ -42,9 +42,7 @@ namespace ModernKeePass.Views
protected override void OnNavigatedTo(NavigationEventArgs e)
{
NavigationHelper.OnNavigatedTo(e);
- /*if (!(e.Parameter is EntryVm)) return;
- DataContext = (EntryVm)e.Parameter;*/
- var args = e.Parameter as Application.Entry.Models.EntryVm;
+ var args = e.Parameter as string;
if (args != null) DataContext = new EntryDetailVm(args);
}
diff --git a/ModernKeePass/Views/GroupDetailPage.xaml.cs b/ModernKeePass/Views/GroupDetailPage.xaml.cs
index 182f478..9f4ec59 100644
--- a/ModernKeePass/Views/GroupDetailPage.xaml.cs
+++ b/ModernKeePass/Views/GroupDetailPage.xaml.cs
@@ -50,12 +50,12 @@ namespace ModernKeePass.Views
var args = e.Parameter as PasswordEventArgs;
if (args != null)
- DataContext = new GroupDetailVm(args.RootGroup);
+ DataContext = new GroupDetailVm(args.RootGroupId);
else
{
- var vm = e.Parameter as Application.Group.Models.GroupVm;
- if (vm != null)
- DataContext = new GroupDetailVm(vm);
+ var id = e.Parameter as string;
+ if (id != null)
+ DataContext = new GroupDetailVm(id);
}
}
@@ -77,7 +77,7 @@ namespace ModernKeePass.Views
return;
default:
var group = listView?.SelectedItem as Application.Group.Models.GroupVm;
- Frame.Navigate(typeof(GroupDetailPage), group);
+ Frame.Navigate(typeof(GroupDetailPage), group?.Id);
break;
}
}
@@ -90,7 +90,7 @@ namespace ModernKeePass.Views
return;
default:
var entry = GridView.SelectedItem as EntryVm;
- Frame.Navigate(typeof(EntryDetailPage), entry);
+ Frame.Navigate(typeof(EntryDetailPage), entry?.Id);
break;
}
}
@@ -124,7 +124,7 @@ namespace ModernKeePass.Views
var results = Model.SubEntries.Where(e => e.Title.IndexOf(args.QueryText, StringComparison.OrdinalIgnoreCase) >= 0).Take(5);
foreach (var result in results)
{
- args.Request.SearchSuggestionCollection.AppendResultSuggestion(result.Title, result.ParentGroup.Title, result.Id, imageUri, string.Empty);
+ args.Request.SearchSuggestionCollection.AppendResultSuggestion(result.Title, result.ParentGroupName, result.Id, imageUri, string.Empty);
}
}
diff --git a/ModernKeePass/Views/UserControls/BreadCrumbUserControl.xaml b/ModernKeePass/Views/UserControls/BreadCrumbUserControl.xaml
index 9a3de5b..1872a38 100644
--- a/ModernKeePass/Views/UserControls/BreadCrumbUserControl.xaml
+++ b/ModernKeePass/Views/UserControls/BreadCrumbUserControl.xaml
@@ -19,7 +19,7 @@
-
+
@@ -32,7 +32,7 @@
-
+
diff --git a/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml.cs b/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml.cs
index 6ca4515..96e6c83 100644
--- a/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml.cs
+++ b/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml.cs
@@ -95,7 +95,7 @@ namespace ModernKeePass.Views.UserControls
if (UpdateKey)
{
await Model.UpdateKey();
- ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroup));
+ ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroupId));
}
else
{
@@ -175,7 +175,7 @@ namespace ModernKeePass.Views.UserControls
ButtonLabel = resource.GetResourceValue("CompositeKeyOpening");
if (await Dispatcher.RunTaskAsync(async () => await Model.OpenDatabase(DatabaseFile, CreateNew)))
{
- ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroup));
+ ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroupId));
}
ButtonLabel = oldLabel;