using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Domain.Entities;
using MediatR;
namespace EnvelopeGenerator.Application.Common.Notifications.RemoveSignature.Handlers;
///
///
///
public class RemoveDocResult : INotificationHandler
{
private readonly IRepository _repo;
///
///
///
///
public RemoveDocResult(IRepository repository)
{
_repo = repository;
}
///
///
///
///
///
///
public Task Handle(RemoveSignatureNotification notification, CancellationToken cancel)
{
if(notification.EnvelopeId is null && notification.EnvelopeUuid is null)
return Task.CompletedTask;
return _repo.UpdateAsync(
envelope => envelope.DocResult = null,
query => {
if (notification.EnvelopeId is int envelopeId)
query = query.Where(envelope => envelope.Id == envelopeId);
if (notification.EnvelopeUuid is string uuid)
query = query.Where(envelope => envelope.Uuid == uuid);
return query;
}, cancel);
}
}