diff --git a/ModernKeePass.Application/Application.csproj b/ModernKeePass.Application/Application.csproj
index 309be71..b2def2c 100644
--- a/ModernKeePass.Application/Application.csproj
+++ b/ModernKeePass.Application/Application.csproj
@@ -67,6 +67,7 @@
+
@@ -80,25 +81,22 @@
+
-
-
-
-
diff --git a/ModernKeePass.Application/Common/Interfaces/IDatabaseProxy.cs b/ModernKeePass.Application/Common/Interfaces/IDatabaseProxy.cs
index d1cc6ba..61cd1f0 100644
--- a/ModernKeePass.Application/Common/Interfaces/IDatabaseProxy.cs
+++ b/ModernKeePass.Application/Common/Interfaces/IDatabaseProxy.cs
@@ -26,8 +26,8 @@ namespace ModernKeePass.Application.Common.Interfaces
Task AddEntry(string parentGroupId, string entryId);
Task AddGroup(string parentGroupId, string groupId);
- Task UpdateEntry(string entryId);
- Task UpdateGroup(string groupId);
+ void UpdateEntry(string entryId, string fieldName, string fieldValue);
+ void UpdateGroup(string groupId);
Task RemoveEntry(string parentGroupId, string entryId);
Task RemoveGroup(string parentGroupId, string groupId);
EntryEntity CreateEntry(string parentGroupId);
diff --git a/ModernKeePass.Application/Entry/Commands/SetFieldValue/SetFieldValueCommand.cs b/ModernKeePass.Application/Entry/Commands/SetFieldValue/SetFieldValueCommand.cs
new file mode 100644
index 0000000..11cc4ab
--- /dev/null
+++ b/ModernKeePass.Application/Entry/Commands/SetFieldValue/SetFieldValueCommand.cs
@@ -0,0 +1,35 @@
+using System.Threading.Tasks;
+using MediatR;
+using ModernKeePass.Application.Common.Interfaces;
+using ModernKeePass.Application.Database.Queries.IsDatabaseOpen;
+using ModernKeePass.Domain.Exceptions;
+
+namespace ModernKeePass.Application.Entry.Commands.SetFieldValue
+{
+ public class SetFieldValueCommand : IRequest
+ {
+ public string EntryId { get; set; }
+ public string FieldName { get; set; }
+ public string FieldValue { get; set; }
+
+ public class SetFieldValueCommandHandler : IAsyncRequestHandler
+ {
+ private readonly IDatabaseProxy _database;
+ private readonly IMediator _mediator;
+
+ public SetFieldValueCommandHandler(IDatabaseProxy database, IMediator mediator)
+ {
+ _database = database;
+ _mediator = mediator;
+ }
+
+ public async Task Handle(SetFieldValueCommand message)
+ {
+ var isDatabaseOpen = await _mediator.Send(new IsDatabaseOpenQuery());
+ if (!isDatabaseOpen) throw new DatabaseClosedException();
+
+ _database.UpdateEntry(message.EntryId, message.FieldName, message.FieldValue);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ModernKeePass.Application/Resources/Queries/GetResourceQuery.cs b/ModernKeePass.Application/Resources/Queries/GetResourceQuery.cs
new file mode 100644
index 0000000..fde20ef
--- /dev/null
+++ b/ModernKeePass.Application/Resources/Queries/GetResourceQuery.cs
@@ -0,0 +1,23 @@
+using MediatR;
+using ModernKeePass.Application.Common.Interfaces;
+
+namespace ModernKeePass.Application.Resources.Queries
+{
+ public class GetResourceQuery: IRequest
+ {
+ public string Key { get; set; }
+ public class GetResourceQueryHandler: IRequestHandler
+ {
+ private readonly IResourceProxy _resourceProxy;
+
+ public GetResourceQueryHandler(IResourceProxy resourceProxy)
+ {
+ _resourceProxy = resourceProxy;
+ }
+ public string Handle(GetResourceQuery message)
+ {
+ return _resourceProxy.GetResourceValue(message.Key);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ModernKeePass.Application/Services/ResourceService.cs b/ModernKeePass.Application/Services/ResourceService.cs
deleted file mode 100644
index 8f3e920..0000000
--- a/ModernKeePass.Application/Services/ResourceService.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using ModernKeePass.Application.Common.Interfaces;
-using ModernKeePass.Domain.Interfaces;
-
-namespace ModernKeePass.Application.Services
-{
- public class ResourceService: IResourceService
- {
- private readonly IResourceProxy _resourceProxy;
-
- public ResourceService(IResourceProxy resourceProxy)
- {
- _resourceProxy = resourceProxy;
- }
-
- public string GetResourceValue(string key)
- {
- return _resourceProxy.GetResourceValue(key);
- }
- }
-}
\ No newline at end of file
diff --git a/ModernKeePass.Domain/Domain.csproj b/ModernKeePass.Domain/Domain.csproj
index 13f6177..b933f71 100644
--- a/ModernKeePass.Domain/Domain.csproj
+++ b/ModernKeePass.Domain/Domain.csproj
@@ -47,6 +47,7 @@
+
diff --git a/ModernKeePass.Domain/Enums/EntryFieldName.cs b/ModernKeePass.Domain/Enums/EntryFieldName.cs
new file mode 100644
index 0000000..4b89c83
--- /dev/null
+++ b/ModernKeePass.Domain/Enums/EntryFieldName.cs
@@ -0,0 +1,14 @@
+namespace ModernKeePass.Domain.Enums
+{
+ public class EntryFieldName
+ {
+ public const string Title = nameof(Title);
+ public const string UserName = nameof(UserName);
+ public const string Password = nameof(Password);
+ public const string Url = nameof(Url);
+ public const string Notes = nameof(Notes);
+ public const string Icon = nameof(Icon);
+ public const string ExpirationDate = nameof(ExpirationDate);
+ public const string HasExpirationDate = nameof(HasExpirationDate);
+ }
+}
\ No newline at end of file
diff --git a/ModernKeePass.Infrastructure/Infrastructure.csproj b/ModernKeePass.Infrastructure/Infrastructure.csproj
index 446a8dc..1a05db5 100644
--- a/ModernKeePass.Infrastructure/Infrastructure.csproj
+++ b/ModernKeePass.Infrastructure/Infrastructure.csproj
@@ -44,6 +44,7 @@
+
diff --git a/ModernKeePass.Infrastructure/KeePass/EntryFieldMapper.cs b/ModernKeePass.Infrastructure/KeePass/EntryFieldMapper.cs
new file mode 100644
index 0000000..05dc2b8
--- /dev/null
+++ b/ModernKeePass.Infrastructure/KeePass/EntryFieldMapper.cs
@@ -0,0 +1,33 @@
+using ModernKeePass.Domain.Enums;
+using ModernKeePassLib;
+
+namespace ModernKeePass.Infrastructure.KeePass
+{
+ public static class EntryFieldMapper
+ {
+ public static string MapPwDefsToField(string value)
+ {
+ switch (value)
+ {
+ case PwDefs.TitleField: return EntryFieldName.Title;
+ case PwDefs.UserNameField: return EntryFieldName.UserName;
+ case PwDefs.PasswordField: return EntryFieldName.Password;
+ case PwDefs.NotesField: return EntryFieldName.Notes;
+ case PwDefs.UrlField: return EntryFieldName.Url;
+ default: return value;
+ }
+ }
+ public static string MapFieldToPwDef(string value)
+ {
+ switch (value)
+ {
+ case EntryFieldName.Title: return PwDefs.TitleField;
+ case EntryFieldName.UserName: return PwDefs.UserNameField;
+ case EntryFieldName.Password: return PwDefs.PasswordField;
+ case EntryFieldName.Notes: return PwDefs.NotesField;
+ case EntryFieldName.Url: return PwDefs.UrlField;
+ default: return value;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs b/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs
index d29cd25..daf6d2a 100644
--- a/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs
+++ b/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs
@@ -10,6 +10,7 @@ using ModernKeePassLib;
using ModernKeePassLib.Cryptography.KeyDerivation;
using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Keys;
+using ModernKeePassLib.Security;
using ModernKeePassLib.Serialization;
using ModernKeePassLib.Utility;
@@ -196,12 +197,15 @@ namespace ModernKeePass.Infrastructure.KeePass
});
}
- public Task UpdateEntry(string entry)
+ public void UpdateEntry(string entryId, string fieldName, string fieldValue)
{
- throw new NotImplementedException();
+ var pwEntry = _pwDatabase.RootGroup.FindEntry(BuildIdFromString(entryId), true);
+ pwEntry.Touch(true);
+ pwEntry.CreateBackup(null);
+ pwEntry.Strings.Set(EntryFieldMapper.MapFieldToPwDef(fieldName), new ProtectedString(true, fieldValue));
}
- public Task UpdateGroup(string group)
+ public void UpdateGroup(string group)
{
throw new NotImplementedException();
}