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