53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using AngleSharp.Html;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.Common.Notifications.RemoveSignature.Handlers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class RemoveDocStatusHandler : INotificationHandler<RemoveSignatureNotification>
|
|
{
|
|
private readonly IRepository<Domain.Entities.DocumentStatus> _repo;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
public RemoveDocStatusHandler(IRepository<Domain.Entities.DocumentStatus> repository)
|
|
{
|
|
_repo = repository;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="notification"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public Task Handle(RemoveSignatureNotification notification, CancellationToken cancel)
|
|
{
|
|
notification.ThrowIfHasNoFilter();
|
|
return _repo.DeleteAsync(statuses =>
|
|
{
|
|
// envelope ID filter
|
|
if (notification.EnvelopeId is int envelopeId)
|
|
statuses = statuses.Where(status => status.EnvelopeId == envelopeId);
|
|
|
|
// envelope UUID filter
|
|
if (notification.EnvelopeUuid is string envelopeUuid)
|
|
statuses = statuses.Where(status => status.Envelope!.Uuid == envelopeUuid);
|
|
|
|
// receiver Id filter
|
|
if (notification.ReceiverId is int receiverId)
|
|
statuses = statuses.Where(status => status.ReceiverId == receiverId);
|
|
|
|
// receiver signature filter
|
|
if (notification.ReceiverSignature is string receiverSignature)
|
|
statuses = statuses.Where(status => status.Receiver!.Signature == receiverSignature);
|
|
|
|
return statuses;
|
|
}, cancel);
|
|
}
|
|
} |