2020-03-26 19:04:51 +01:00
|
|
|
|
using MediatR;
|
2020-03-26 15:38:29 +01:00
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
|
|
|
|
|
2020-05-11 10:53:14 +02:00
|
|
|
|
namespace ModernKeePass.Application.Entry.Commands.UpsertField
|
2020-03-26 15:38:29 +01:00
|
|
|
|
{
|
2020-05-11 10:53:14 +02:00
|
|
|
|
public class UpsertFieldCommand : IRequest
|
2020-03-26 15:38:29 +01:00
|
|
|
|
{
|
|
|
|
|
public string EntryId { get; set; }
|
|
|
|
|
public string FieldName { get; set; }
|
2020-03-27 13:27:29 +01:00
|
|
|
|
public object FieldValue { get; set; }
|
2020-03-26 15:38:29 +01:00
|
|
|
|
|
2020-05-11 10:53:14 +02:00
|
|
|
|
public class UpsertFieldCommandHandler : IRequestHandler<UpsertFieldCommand>
|
2020-03-26 15:38:29 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
2020-05-11 10:53:14 +02:00
|
|
|
|
public UpsertFieldCommandHandler(IDatabaseProxy database)
|
2020-03-26 15:38:29 +01:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 10:53:14 +02:00
|
|
|
|
public void Handle(UpsertFieldCommand message)
|
2020-03-26 15:38:29 +01:00
|
|
|
|
{
|
2020-03-26 19:04:51 +01:00
|
|
|
|
if (!_database.IsOpen) throw new DatabaseClosedException();
|
2020-03-26 15:38:29 +01:00
|
|
|
|
|
|
|
|
|
_database.UpdateEntry(message.EntryId, message.FieldName, message.FieldValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|