78 lines
2.5 KiB
C#
78 lines
2.5 KiB
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using DigitalData.Core.Exceptions;
|
|
using EnvelopeGenerator.Application.Model;
|
|
using EnvelopeGenerator.Domain;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Application.Extensions;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public record ReceiverAlreadySignedQuery : EnvelopeReceiverQueryBase, IRequest<bool>;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public static class ReceiverAlreadySignedQueryExtensions
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="mediator"></param>
|
|
/// <param name="key"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public static Task<bool> IsSignedAsync(this IMediator mediator, string key, CancellationToken cancel = default)
|
|
=> mediator.Send(new ReceiverAlreadySignedQuery { Key = key }, cancel);
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="mediator"></param>
|
|
/// <param name="uuid"></param>
|
|
/// <param name="signature"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public static Task<bool> IsSignedAsync(this IMediator mediator, string uuid, string signature, CancellationToken cancel = default)
|
|
=> mediator.Send(new ReceiverAlreadySignedQuery
|
|
{
|
|
Envelope = new() { Uuid = uuid },
|
|
Receiver = new() { Signature = signature }
|
|
}, cancel);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ReceiverAlreadySignedQueryHandler : IRequestHandler<ReceiverAlreadySignedQuery, bool>
|
|
{
|
|
private readonly IRepository<EnvelopeReceiver> _repo;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repo"></param>
|
|
public ReceiverAlreadySignedQueryHandler(IRepository<EnvelopeReceiver> repo)
|
|
{
|
|
_repo = repo;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> Handle(ReceiverAlreadySignedQuery request, CancellationToken cancel = default)
|
|
{
|
|
return await _repo.Read()
|
|
.Where(er => er.Envelope.Uuid == request.Envelope.Uuid)
|
|
.Where(er => er.Receiver.Signature == request.Receiver.Signature)
|
|
.Where(er => er.Envelope.History.Any(hist => hist.Status == Constants.EnvelopeStatus.DocumentSigned))
|
|
.AnyAsync(cancel);
|
|
}
|
|
} |