Updated IEnvelopeHistoryRepository and IEnvelopeHistoryService interfaces to replace int? status with Constants.EnvelopeStatus? status in CountAsync and ReadAsync methods. Adjusted ReadHistoryQueryHandler and EnvelopeHistoryService methods to accommodate the new type. Modified EnvelopeHistoryRepository to accept Constants.EnvelopeStatus? in relevant methods and marked it as obsolete, suggesting a future refactor.
155 lines
6.1 KiB
C#
155 lines
6.1 KiB
C#
using AutoMapper;
|
|
using DigitalData.Core.Application;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Application.Contracts.Repositories;
|
|
using static EnvelopeGenerator.Domain.Constants;
|
|
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
|
|
using EnvelopeGenerator.Application.DTOs.Receiver;
|
|
using EnvelopeGenerator.Application.Contracts.Services;
|
|
using DigitalData.Core.Abstraction.Application.DTO;
|
|
|
|
namespace EnvelopeGenerator.Application.Services;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Obsolete("Use MediatR")]
|
|
public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, EnvelopeHistoryCreateDto, EnvelopeHistoryDto, EnvelopeHistory, long>, IEnvelopeHistoryService
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
/// <param name="mapper"></param>
|
|
public EnvelopeHistoryService(IEnvelopeHistoryRepository repository, IMapper mapper)
|
|
: base(repository, mapper)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// /
|
|
/// </summary>
|
|
/// <param name="envelopeId"></param>
|
|
/// <param name="userReference"></param>
|
|
/// <param name="status"></param>
|
|
/// <returns></returns>
|
|
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null) => await _repository.CountAsync(envelopeId: envelopeId, userReference: userReference, status: status);
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="status"></param>
|
|
/// <param name="envelopeId"></param>
|
|
/// <param name="userReference"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> HasStatus(EnvelopeStatus status, int envelopeId, string userReference) => await _repository.CountAsync(
|
|
envelopeId: envelopeId,
|
|
userReference: userReference,
|
|
status: status) > 0;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeId"></param>
|
|
/// <param name="userReference"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AccessCodeAlreadyRequested(int envelopeId, string userReference) => await _repository.CountAsync(
|
|
envelopeId: envelopeId,
|
|
userReference:userReference,
|
|
status: EnvelopeStatus.AccessCodeRequested) > 0;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeId"></param>
|
|
/// <param name="userReference"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> IsSigned(int envelopeId, string userReference) => await _repository.CountAsync(
|
|
envelopeId: envelopeId,
|
|
userReference: userReference,
|
|
status: EnvelopeStatus.DocumentSigned) > 0;
|
|
|
|
/// <summary>
|
|
/// Checks if the specified envelope has been rejected.
|
|
/// <para><b>Note:</b> <i>If any document within the envelope is rejected, the entire envelope will be considered rejected.</i></para>
|
|
/// </summary>
|
|
/// <param name="envelopeId">The ID of the envelope to check.</param>
|
|
/// <param name="userReference">Optional user reference associated with the envelope.</param>
|
|
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the envelope is rejected.</returns>
|
|
public async Task<bool> IsRejected(int envelopeId, string? userReference = null)
|
|
{
|
|
return await _repository.CountAsync(
|
|
envelopeId: envelopeId,
|
|
userReference: userReference,
|
|
status: EnvelopeStatus.DocumentRejected) > 0;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeId"></param>
|
|
/// <param name="userReference"></param>
|
|
/// <param name="referenceType"></param>
|
|
/// <param name="status"></param>
|
|
/// <param name="withSender"></param>
|
|
/// <param name="withReceiver"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false)
|
|
{
|
|
var histDTOs = _mapper.Map<IEnumerable<EnvelopeHistoryDto>>(
|
|
await _repository.ReadAsync(
|
|
envelopeId: envelopeId,
|
|
userReference: userReference,
|
|
status: status,
|
|
withSender: withSender,
|
|
withReceiver: withReceiver));
|
|
return referenceType is null ? histDTOs : histDTOs.Where(h => h.ReferenceType == referenceType);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeId"></param>
|
|
/// <param name="userReference"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null) =>
|
|
await ReadAsync(envelopeId: envelopeId, userReference: userReference, status: EnvelopeStatus.DocumentRejected, withReceiver:true);
|
|
|
|
//TODO: use IQueryable in repository to incerease the performance
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeId"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<ReceiverReadDto>> ReadRejectingReceivers(int envelopeId)
|
|
{
|
|
var envelopes = await ReadRejectedAsync(envelopeId);
|
|
return envelopes is null
|
|
? Enumerable.Empty<ReceiverReadDto>()
|
|
: envelopes
|
|
.Where(eh => eh?.Receiver != null)
|
|
.Select(eh => eh.Receiver!);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeId"></param>
|
|
/// <param name="userReference"></param>
|
|
/// <param name="status"></param>
|
|
/// <param name="comment"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult<long>> RecordAsync(int envelopeId, string userReference, EnvelopeStatus status, string? comment = null) =>
|
|
await CreateAsync(new ()
|
|
{
|
|
EnvelopeId = envelopeId,
|
|
UserReference = userReference,
|
|
Status = (int) status,
|
|
ActionDate = DateTime.Now,
|
|
Comment = comment
|
|
})
|
|
.ThenAsync(
|
|
Success: dto => Result.Success(dto.Id),
|
|
Fail: (mssg, ntc) => Result.Fail<long>().Message(mssg).Notice(ntc)
|
|
);
|
|
} |