2020-05-18 14:14:28 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
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-05-12 17:14:30 +02:00
|
|
|
|
public bool IsProtected { get; set; } = true;
|
2020-03-26 15:38:29 +01:00
|
|
|
|
|
2020-05-18 14:14:28 +02:00
|
|
|
|
public class UpsertFieldCommandHandler : IAsyncRequestHandler<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-18 14:14:28 +02:00
|
|
|
|
public async Task 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
|
|
|
|
|
2020-05-18 14:14:28 +02:00
|
|
|
|
await _database.UpdateEntry(message.EntryId, message.FieldName, message.FieldValue, message.IsProtected);
|
2020-03-26 15:38:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|