83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using EnvelopeGenerator.Application.Exceptions;
|
|
using EnvelopeGenerator.Domain;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Extensions;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public record ReceiverAlreadySignedQuery : IRequest<bool>
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public required string Key
|
|
{
|
|
get => (EnvelopeUuid, ReceiverSignature).EncodeEnvelopeReceiverId();
|
|
init
|
|
{
|
|
(string? EnvelopeUuid, string? ReceiverSignature) = value.DecodeEnvelopeReceiverId();
|
|
if (string.IsNullOrEmpty(EnvelopeUuid) || string.IsNullOrEmpty(ReceiverSignature))
|
|
{
|
|
throw new BadRequestException("Der EnvelopeReceiverKey muss ein gültiger Base64-kodierter String sein, der die EnvelopeUuid und die ReceiverSignature enthält.");
|
|
}
|
|
}
|
|
}
|
|
|
|
internal string EnvelopeUuid { get; set; } = null!;
|
|
|
|
internal string ReceiverSignature { get; set; } = null!;
|
|
}
|
|
|
|
/// <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> ReceiverAlreadySigned(this IMediator mediator, string key, CancellationToken cancel = default)
|
|
=> mediator.Send(new ReceiverAlreadySignedQuery { Key = key }, 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.EnvelopeUuid)
|
|
.Where(er => er.Receiver.Signature == request.ReceiverSignature)
|
|
.Where(er => er.Envelope.History.Any(hist => hist.Status == Constants.EnvelopeStatus.DocumentSigned))
|
|
.AnyAsync(cancel);
|
|
}
|
|
} |