mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Build hierarchy instead of using Automapper
Add entities before removing them
This commit is contained in:
@@ -22,7 +22,7 @@ using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class EntryVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
public class EntryDetailVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
{
|
||||
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
|
||||
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
|
||||
@@ -68,11 +68,7 @@ namespace ModernKeePass.ViewModels
|
||||
public string UserName
|
||||
{
|
||||
get { return _entry.Username; }
|
||||
set
|
||||
{
|
||||
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(UserName), FieldValue = value }).Wait();
|
||||
_entry.Username = value;
|
||||
}
|
||||
set { _entry.Username = value; }
|
||||
}
|
||||
|
||||
public string Password
|
||||
@@ -225,11 +221,11 @@ namespace ModernKeePass.ViewModels
|
||||
private double _passwordLength = 25;
|
||||
private bool _isVisible = true;
|
||||
|
||||
public EntryVm() { }
|
||||
public EntryDetailVm() { }
|
||||
|
||||
internal EntryVm(Application.Entry.Models.EntryVm entry, bool isNewEntry = false) : this(entry, App.Mediator, isNewEntry) { }
|
||||
internal EntryDetailVm(Application.Entry.Models.EntryVm entry, bool isNewEntry = false) : this(entry, App.Mediator, isNewEntry) { }
|
||||
|
||||
public EntryVm(Application.Entry.Models.EntryVm entry, IMediator mediator, bool isNewEntry = false)
|
||||
public EntryDetailVm(Application.Entry.Models.EntryVm entry, IMediator mediator, bool isNewEntry = false)
|
||||
{
|
||||
_entry = entry;
|
||||
_mediator = mediator;
|
||||
@@ -263,19 +259,18 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task MarkForDelete(string recycleBinTitle)
|
||||
{
|
||||
if (_database.IsRecycleBinEnabled && _database.RecycleBin == null)
|
||||
await _mediator.Send(new CreateGroupCommand { ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
|
||||
await Move(_database.IsRecycleBinEnabled && _entry.ParentGroup == _database.RecycleBin ? _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);
|
||||
}
|
||||
|
||||
public async Task Move(Application.Group.Models.GroupVm destination)
|
||||
{
|
||||
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
|
||||
await _mediator.Send(new RemoveEntryCommand { ParentGroup = _entry.ParentGroup, Entry = _entry });
|
||||
if (destination == null)
|
||||
{
|
||||
await _mediator.Send(new DeleteEntryCommand { Entry = _entry });
|
||||
return;
|
||||
}
|
||||
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
|
||||
}
|
||||
|
||||
public async Task CommitDelete()
|
||||
@@ -287,5 +282,10 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
return _entry;
|
||||
}
|
||||
|
||||
public async Task SetFieldValue(string fieldName, object value)
|
||||
{
|
||||
await _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = fieldName, FieldValue = value });
|
||||
}
|
||||
}
|
||||
}
|
@@ -26,7 +26,7 @@ using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class GroupVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
public class GroupDetailVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
{
|
||||
public ObservableCollection<Application.Entry.Models.EntryVm> Entries => new ObservableCollection<Application.Entry.Models.EntryVm>(_group.Entries);
|
||||
|
||||
@@ -47,7 +47,6 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsNotRoot => _database.RootGroup != _group;
|
||||
|
||||
public bool ShowRestore => IsNotRoot && _database.RecycleBin != _group;
|
||||
@@ -117,12 +116,12 @@ namespace ModernKeePass.ViewModels
|
||||
private Application.Entry.Models.EntryVm _reorderedEntry;
|
||||
private bool _isMenuClosed = true;
|
||||
|
||||
public GroupVm() {}
|
||||
public GroupDetailVm() {}
|
||||
|
||||
internal GroupVm(Application.Group.Models.GroupVm group) : this(group, App.Mediator)
|
||||
internal GroupDetailVm(Application.Group.Models.GroupVm group) : this(group, App.Mediator)
|
||||
{ }
|
||||
|
||||
public GroupVm(Application.Group.Models.GroupVm group, IMediator mediator, bool isEditMode = false)
|
||||
public GroupDetailVm(Application.Group.Models.GroupVm group, IMediator mediator, bool isEditMode = false)
|
||||
{
|
||||
_group = group;
|
||||
_mediator = mediator;
|
||||
@@ -151,7 +150,7 @@ namespace ModernKeePass.ViewModels
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
if (_reorderedEntry == null)
|
||||
{
|
||||
var entry = ((EntryVm) e.NewItems[0]).GetEntry();
|
||||
var entry = ((EntryDetailVm) e.NewItems[0]).GetEntry();
|
||||
await _mediator.Send(new AddEntryCommand {Entry = entry, ParentGroup = _group});
|
||||
}
|
||||
else
|
||||
@@ -175,20 +174,19 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task MarkForDelete(string recycleBinTitle)
|
||||
{
|
||||
if (_database.IsRecycleBinEnabled && _database.RecycleBin == null)
|
||||
await _mediator.Send(new CreateGroupCommand {ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
|
||||
_database.RecycleBin = await _mediator.Send(new CreateGroupCommand {ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
|
||||
await Move(_database.IsRecycleBinEnabled && !IsSelected ? _database.RecycleBin : null);
|
||||
((RelayCommand)UndoDeleteCommand).RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
public async Task Move(Application.Group.Models.GroupVm destination)
|
||||
{
|
||||
await _mediator.Send(new AddGroupCommand {ParentGroup = destination, Group = _group});
|
||||
await _mediator.Send(new RemoveGroupCommand {ParentGroup = _group.ParentGroup, Group = _group});
|
||||
if (destination == null)
|
||||
{
|
||||
await _mediator.Send(new DeleteGroupCommand { Group = _group });
|
||||
return;
|
||||
}
|
||||
await _mediator.Send(new AddGroupCommand {ParentGroup = destination, Group = _group});
|
||||
}
|
||||
|
||||
public async Task CommitDelete()
|
@@ -23,7 +23,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
private GroupVm _selectedItem;
|
||||
private GroupDetailVm _selectedItem;
|
||||
|
||||
public bool HasRecycleBin
|
||||
{
|
||||
@@ -104,7 +104,7 @@ namespace ModernKeePass.ViewModels
|
||||
_selectedItem.IsSelected = false;
|
||||
}
|
||||
|
||||
SetProperty(ref _selectedItem, (GroupVm)value);
|
||||
SetProperty(ref _selectedItem, (GroupDetailVm)value);
|
||||
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
|
Reference in New Issue
Block a user