From 0818b8d60600216db5553fa46fc3ad9da3eea171 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 3 Jun 2024 10:15:26 +0200 Subject: [PATCH] =?UTF-8?q?IsRejected=20und=20ReadRejectedAsync=20Methoden?= =?UTF-8?q?=20zu=20EnvelopeHistoryService=20hinzugef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contracts/IEnvelopeHistoryService.cs | 2 ++ .../Services/EnvelopeHistoryService.cs | 21 +++++++++++++++++++ .../Contracts/IEnvelopeHistoryRepository.cs | 2 ++ .../Repositories/EnvelopeHistoryRepository.cs | 16 +++++++++++--- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/EnvelopeGenerator.Application/Contracts/IEnvelopeHistoryService.cs b/EnvelopeGenerator.Application/Contracts/IEnvelopeHistoryService.cs index 6a1f4eda..3668bc7d 100644 --- a/EnvelopeGenerator.Application/Contracts/IEnvelopeHistoryService.cs +++ b/EnvelopeGenerator.Application/Contracts/IEnvelopeHistoryService.cs @@ -15,6 +15,8 @@ namespace EnvelopeGenerator.Application.Contracts Task IsSigned(int envelopeId, string userReference); + Task> ReadRejectedAsync(int envelopeId, string? userReference = null); + Task> RecordAsync(int envelopeId, string userReference, EnvelopeStatus status); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs index 94fdd471..fcfd719c 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs @@ -35,6 +35,27 @@ namespace EnvelopeGenerator.Application.Services userReference: userReference, status: (int) EnvelopeStatus.DocumentSigned) > 0; + /// + /// Checks if the specified envelope has been rejected. + /// Note: If any document within the envelope is rejected, the entire envelope will be considered rejected. + /// + /// The ID of the envelope to check. + /// Optional user reference associated with the envelope. + /// A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the envelope is rejected. + public async Task IsRejected(int envelopeId, string? userReference = null) + { + return await _repository.CountAsync( + envelopeId: envelopeId, + userReference: userReference, + status: (int)EnvelopeStatus.DocumentRejected) > 0; + } + + public async Task> ReadRejectedAsync(int envelopeId, string? userReference = null) => _mapper.MapOrThrow>( + await _repository.ReadAsync( + envelopeId: envelopeId, + userReference: userReference, + status: (int)EnvelopeStatus.DocumentRejected)); + public async Task> RecordAsync(int envelopeId, string userReference, EnvelopeStatus status) => await CreateAsync(new (EnvelopeId: envelopeId, UserReference: userReference, Status: (int)status, ActionDate: DateTime.Now)) .ThenAsync( diff --git a/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeHistoryRepository.cs b/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeHistoryRepository.cs index e442dac2..99e95e7b 100644 --- a/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeHistoryRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeHistoryRepository.cs @@ -6,5 +6,7 @@ namespace EnvelopeGenerator.Infrastructure.Contracts public interface IEnvelopeHistoryRepository : ICRUDRepository { Task CountAsync(int? envelopeId = null, string? userReference = null, int? status = null); + + Task> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs index e27286fa..d89f4493 100644 --- a/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs @@ -12,10 +12,10 @@ namespace EnvelopeGenerator.Infrastructure.Repositories { } - public async Task CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) + private IQueryable By(int? envelopeId = null, string? userReference = null, int? status = null) { var query = _dbSet.AsQueryable(); - + if (envelopeId is not null) query = query.Where(eh => eh.EnvelopeId == envelopeId); @@ -25,7 +25,17 @@ namespace EnvelopeGenerator.Infrastructure.Repositories if (status is not null) query = query.Where(eh => eh.Status == status); - return await query.CountAsync(); + return query; } + + public async Task CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await By( + envelopeId: envelopeId, + userReference: userReference, + status: status).CountAsync(); + + public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await By( + envelopeId: envelopeId, + userReference: userReference, + status: status).ToListAsync(); } } \ No newline at end of file