73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Application.Common.Extensions;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using EnvelopeGenerator.Application.Common.Query;
|
|
|
|
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<History> _repo;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repo"></param>
|
|
public ReceiverAlreadySignedQueryHandler(IRepository<History> 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.ReadOnly().Where(request).Where(h => h.Status == EnvelopeStatus.DocumentSigned).AnyAsync(cancel);
|
|
}
|
|
} |