56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using EnvelopeGenerator.Application.Common.Extensions;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.Common.Notifications.RemoveSignature.Handlers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class RemoveHistoryHandler : INotificationHandler<RemoveSignatureNotification>
|
|
{
|
|
private readonly IRepository<Domain.Entities.History> _repo;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
public RemoveHistoryHandler(IRepository<Domain.Entities.History> 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(hists =>
|
|
{
|
|
hists = hists.Where(hist => hist.Status == EnvelopeStatus.DocumentSigned);
|
|
|
|
// envelope ID filter
|
|
if (notification.EnvelopeId is int envelopeId)
|
|
hists = hists.Where(hist => hist.EnvelopeId == envelopeId);
|
|
|
|
// envelope UUID filter
|
|
if (notification.EnvelopeUuid is string envelopeUuid)
|
|
hists = hists.Where(hist => hist.Envelope!.Uuid == envelopeUuid);
|
|
|
|
// receiver ID filter
|
|
if (notification.ReceiverId is int receiverId)
|
|
hists = hists.Where(hist => hist.Receiver!.Id == receiverId);
|
|
|
|
// receiver signature filter
|
|
if (notification.ReceiverSignature is string receiverSignature)
|
|
hists = hists.Where(hist => hist.Receiver!.Signature == receiverSignature);
|
|
|
|
return hists;
|
|
}, cancel);
|
|
}
|
|
} |