diff --git a/EnvelopeGenerator.Application/Contracts/IEnvelopeHistoryService.cs b/EnvelopeGenerator.Application/Contracts/IEnvelopeHistoryService.cs index 3668bc7d..cd8bb1fb 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> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null); + Task> ReadRejectedAsync(int envelopeId, string? userReference = null); Task> RecordAsync(int envelopeId, string userReference, EnvelopeStatus status); diff --git a/EnvelopeGenerator.Application/DTOs/EnvelopeHistory/EnvelopeHistoryDto.cs b/EnvelopeGenerator.Application/DTOs/EnvelopeHistory/EnvelopeHistoryDto.cs index deef909e..e98ca6db 100644 --- a/EnvelopeGenerator.Application/DTOs/EnvelopeHistory/EnvelopeHistoryDto.cs +++ b/EnvelopeGenerator.Application/DTOs/EnvelopeHistory/EnvelopeHistoryDto.cs @@ -7,5 +7,6 @@ int Status, DateTime AddedWhen, DateTime? ActionDate, + ReceiverDto? Receiver, string? Comment = null); } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs index fcfd719c..30509af7 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs @@ -50,11 +50,14 @@ namespace EnvelopeGenerator.Application.Services status: (int)EnvelopeStatus.DocumentRejected) > 0; } - public async Task> ReadRejectedAsync(int envelopeId, string? userReference = null) => _mapper.MapOrThrow>( + public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null) => _mapper.MapOrThrow>( await _repository.ReadAsync( envelopeId: envelopeId, userReference: userReference, - status: (int)EnvelopeStatus.DocumentRejected)); + status: status)); + + public async Task> ReadRejectedAsync(int envelopeId, string? userReference = null) => + await 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)) diff --git a/EnvelopeGenerator.Domain/Entities/EnvelopeHistory.cs b/EnvelopeGenerator.Domain/Entities/EnvelopeHistory.cs index 0166f0fb..68a40422 100644 --- a/EnvelopeGenerator.Domain/Entities/EnvelopeHistory.cs +++ b/EnvelopeGenerator.Domain/Entities/EnvelopeHistory.cs @@ -33,5 +33,12 @@ namespace EnvelopeGenerator.Domain.Entities [Column("COMMENT", TypeName = "nvarchar(max)")] public string? Comment { get; set; } + + + //[ForeignKey("UserReference")] + //public virtual DigitalData.UserManager.Domain.Entities.User? Sender { get; set; } + + [ForeignKey("UserReference")] + public virtual Receiver? Receiver { get; set; } } } \ No newline at end of file diff --git a/EnvelopeGenerator.Infrastructure/EGDbContext.cs b/EnvelopeGenerator.Infrastructure/EGDbContext.cs index 1a910bcb..895af99f 100644 --- a/EnvelopeGenerator.Infrastructure/EGDbContext.cs +++ b/EnvelopeGenerator.Infrastructure/EGDbContext.cs @@ -48,6 +48,12 @@ namespace DigitalData.UserManager.Infrastructure.Repositories .WithMany(ed => ed.Elements) .HasForeignKey(dre => dre.DocumentId); + modelBuilder.Entity() + .HasOne(eh => eh.Receiver) + .WithMany() + .HasForeignKey(eh => eh.UserReference) + .HasPrincipalKey(e => e.EmailAddress); + // Configure entities to handle database triggers modelBuilder.Entity().ToTable(tb => tb.HasTrigger("TBSIG_ENVELOPE_HISTORY_AFT_INS")); modelBuilder.Entity().ToTable(tb => tb.HasTrigger("TBSIG_ENVELOPE_HISTORY_AFT_INS")); diff --git a/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs index d89f4493..424530da 100644 --- a/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs @@ -12,7 +12,7 @@ namespace EnvelopeGenerator.Infrastructure.Repositories { } - private IQueryable By(int? envelopeId = null, string? userReference = null, int? status = null) + private IQueryable By(int? envelopeId = null, string? userReference = null, int? status = null, bool withReceiver = false) { var query = _dbSet.AsQueryable(); @@ -25,6 +25,11 @@ namespace EnvelopeGenerator.Infrastructure.Repositories if (status is not null) query = query.Where(eh => eh.Status == status); + if(withReceiver) + query = query.Include(eh => eh.Receiver); + + string qSt = query.ToQueryString(); + return query; } @@ -32,10 +37,11 @@ namespace EnvelopeGenerator.Infrastructure.Repositories envelopeId: envelopeId, userReference: userReference, status: status).CountAsync(); - - public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await By( + + public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withReceiver = true) => await By( envelopeId: envelopeId, userReference: userReference, - status: status).ToListAsync(); + status: status, + withReceiver: withReceiver).ToListAsync(); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Web/Controllers/Test/TestEnvelopeHistoryController.cs b/EnvelopeGenerator.Web/Controllers/Test/TestEnvelopeHistoryController.cs index 3fb439c7..5a2c841f 100644 --- a/EnvelopeGenerator.Web/Controllers/Test/TestEnvelopeHistoryController.cs +++ b/EnvelopeGenerator.Web/Controllers/Test/TestEnvelopeHistoryController.cs @@ -24,5 +24,14 @@ namespace EnvelopeGenerator.Web.Controllers.Test { return Ok(await _service.AccessCodeAlreadyRequested(envelopeId, userReference)); } + + [HttpGet] + public async Task GetAsyncWith(int? envelopeId = null, string? userReference = null, int? status = null) + { + return Ok(await _service.ReadAsync(envelopeId: envelopeId, userReference: userReference, status: status)); + } + + [NonAction] + public override Task GetAll() => base.GetAll(); } } \ No newline at end of file