Files
modernkeepass/ModernKeePass.Application/Entry/Commands/UpsertField/UpsertFieldCommand.cs

31 lines
1004 B
C#
Raw Normal View History

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