From 5e5458d87c46c5711462dff55d5c5e02dc7b1157 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 22 Aug 2025 19:19:59 +0200 Subject: [PATCH] fix conflicts after updates --- .../Documents/Queries/ReadDocumentQuery.cs | 17 ++++++++++--- .../Reset/ResetEmailTemplateCommandHandler.cs | 8 +++--- .../UpdateEmailTemplateCommandHandler.cs | 25 ++++++++++++------- .../IEnvelopeReceiverRepository.cs | 3 ++- .../Repositories/IEnvelopeRepository.cs | 3 ++- .../Services/IEnvelopeReceiverService.cs | 3 ++- .../Interfaces/Services/IEnvelopeService.cs | 3 ++- .../Services/EnvelopeReceiverService.cs | 6 +++-- .../Services/EnvelopeService.cs | 5 +++- EnvelopeGenerator.Domain/Entities/Envelope.cs | 4 +-- .../Repositories/EnvelopeRepository.cs | 3 ++- .../Repositories/EnvlopeReceiverRepository.cs | 3 ++- 12 files changed, 57 insertions(+), 26 deletions(-) diff --git a/EnvelopeGenerator.Application/Documents/Queries/ReadDocumentQuery.cs b/EnvelopeGenerator.Application/Documents/Queries/ReadDocumentQuery.cs index bc0a4b43..7e80a9fe 100644 --- a/EnvelopeGenerator.Application/Documents/Queries/ReadDocumentQuery.cs +++ b/EnvelopeGenerator.Application/Documents/Queries/ReadDocumentQuery.cs @@ -2,6 +2,8 @@ using EnvelopeGenerator.Application.Dto; using MediatR; using EnvelopeGenerator.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using AutoMapper; namespace EnvelopeGenerator.Application.Documents.Queries; @@ -24,13 +26,16 @@ public class ReadDocumentQueryHandler : IRequestHandler private readonly IRepository _repo; + private readonly IMapper _mapper; + /// /// Initializes a new instance of the class. /// /// The repository used to access entities. - public ReadDocumentQueryHandler(IRepository envelopeDocumentRepository) + public ReadDocumentQueryHandler(IRepository envelopeDocumentRepository, IMapper mapper) { _repo = envelopeDocumentRepository; + _mapper = mapper; } /// @@ -48,9 +53,15 @@ public class ReadDocumentQueryHandler : IRequestHandler Handle(ReadDocumentQuery query, CancellationToken cancellationToken) { if (query.Id is not null) - return await _repo.ReadOrDefaultAsync(d => d.Id == query.Id); + { + var doc = await _repo.ReadOnly().Where(d => d.Id == query.Id).FirstOrDefaultAsync(); + return _mapper.Map(doc); + } else if (query.EnvelopeId is not null) - return await _repo.ReadOrDefaultAsync(d => d.EnvelopeId == query.EnvelopeId); + { + var doc = await _repo.ReadOnly().Where(d => d.EnvelopeId == query.EnvelopeId).FirstOrDefaultAsync(); + return _mapper.Map(doc); + } throw new InvalidOperationException( $"Invalid {nameof(ReadDocumentQuery)}: either {nameof(query.Id)} or {nameof(query.EnvelopeId)} must be provided."); diff --git a/EnvelopeGenerator.Application/EmailTemplates/Commands/Reset/ResetEmailTemplateCommandHandler.cs b/EnvelopeGenerator.Application/EmailTemplates/Commands/Reset/ResetEmailTemplateCommandHandler.cs index c9faf046..e71c5209 100644 --- a/EnvelopeGenerator.Application/EmailTemplates/Commands/Reset/ResetEmailTemplateCommandHandler.cs +++ b/EnvelopeGenerator.Application/EmailTemplates/Commands/Reset/ResetEmailTemplateCommandHandler.cs @@ -2,6 +2,8 @@ using EnvelopeGenerator.Application.Dto; using EnvelopeGenerator.Domain.Entities; using MediatR; +using Microsoft.EntityFrameworkCore; +using System.Linq; namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Reset; @@ -31,10 +33,10 @@ public class ResetEmailTemplateCommandHandler : IRequestHandler(t => t.Id == request.Id, cancel) + ? await _repository.ReadOnly().Where(t => t.Id == request.Id).ToListAsync(cancel) : request.Type is not null - ? await _repository.ReadAllAsync(t => t.Name == request.Type.ToString(), cancel) - : await _repository.ReadAllAsync(cancellation: cancel); + ? await _repository.ReadOnly().Where(t => t.Name == request.Type.ToString()).ToListAsync(cancel) + : await _repository.ReadOnly().ToListAsync(cancel); foreach (var temp in temps) { diff --git a/EnvelopeGenerator.Application/EmailTemplates/Commands/Update/UpdateEmailTemplateCommandHandler.cs b/EnvelopeGenerator.Application/EmailTemplates/Commands/Update/UpdateEmailTemplateCommandHandler.cs index 1b944c6c..2ca6e643 100644 --- a/EnvelopeGenerator.Application/EmailTemplates/Commands/Update/UpdateEmailTemplateCommandHandler.cs +++ b/EnvelopeGenerator.Application/EmailTemplates/Commands/Update/UpdateEmailTemplateCommandHandler.cs @@ -1,9 +1,11 @@ -using DigitalData.Core.Abstraction.Application.Repository; +using AutoMapper; +using DigitalData.Core.Abstraction.Application.Repository; using EnvelopeGenerator.Application.Dto; using EnvelopeGenerator.Application.Exceptions; using EnvelopeGenerator.Domain; using EnvelopeGenerator.Domain.Entities; using MediatR; +using Microsoft.EntityFrameworkCore; namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Update; @@ -13,14 +15,17 @@ namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Update; public class UpdateEmailTemplateCommandHandler : IRequestHandler { private readonly IRepository _repository; + + private readonly IMapper _mapper; /// /// /// /// - public UpdateEmailTemplateCommandHandler(IRepository repository) + public UpdateEmailTemplateCommandHandler(IRepository repository, IMapper mapper) { _repository = repository; + _mapper = mapper; } /// @@ -34,32 +39,34 @@ public class UpdateEmailTemplateCommandHandler : IRequestHandler instead.")] public async Task Handle(UpdateEmailTemplateCommand request, CancellationToken cancel) { - EmailTemplateDto? temp; + EmailTemplateDto? tempDto; if (request.EmailTemplateQuery?.Id is int id) { - temp = await _repository.ReadOrDefaultAsync(t => t.Id == id, single: false, cancel); + var temp = await _repository.ReadOnly().Where(t => t.Id == id).FirstOrDefaultAsync(cancel); + tempDto = _mapper.Map(temp); } else if (request!.EmailTemplateQuery!.Type is Constants.EmailTemplateType type) { - temp = await _repository.ReadOrDefaultAsync(t => t.Name == type.ToString(), single: false, cancel); + var temp = await _repository.ReadOnly().Where(t => t.Name == type.ToString()).FirstOrDefaultAsync(cancel); + tempDto = _mapper.Map(temp); } else { throw new InvalidOperationException("Both id and type is null. Id: " + request.EmailTemplateQuery.Id +". Type: " + request.EmailTemplateQuery.Type.ToString()); } - if (temp == null) + if (tempDto == null) { throw new NotFoundException(); } if (request.Body is not null) - temp.Body = request.Body; + tempDto.Body = request.Body; if (request.Subject is not null) - temp.Subject = request.Subject; + tempDto.Subject = request.Subject; - await _repository.UpdateAsync(temp, t => t.Id == temp.Id, cancel); + await _repository.UpdateAsync(tempDto, t => t.Id == tempDto.Id, cancel); } } diff --git a/EnvelopeGenerator.Application/Interfaces/Repositories/IEnvelopeReceiverRepository.cs b/EnvelopeGenerator.Application/Interfaces/Repositories/IEnvelopeReceiverRepository.cs index 46f92aac..6797cdfe 100644 --- a/EnvelopeGenerator.Application/Interfaces/Repositories/IEnvelopeReceiverRepository.cs +++ b/EnvelopeGenerator.Application/Interfaces/Repositories/IEnvelopeReceiverRepository.cs @@ -1,4 +1,5 @@ using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Domain; using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.Application.Interfaces.Repositories; @@ -83,7 +84,7 @@ public interface IEnvelopeReceiverRepository : ICRUDRepository /// /// - Task> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses); + Task> ReadByUsernameAsync(string username, Constants.EnvelopeStatus? min_status = null, Constants.EnvelopeStatus? max_status = null, params Constants.EnvelopeStatus[] ignore_statuses); /// /// diff --git a/EnvelopeGenerator.Application/Interfaces/Repositories/IEnvelopeRepository.cs b/EnvelopeGenerator.Application/Interfaces/Repositories/IEnvelopeRepository.cs index 06be0feb..3cada696 100644 --- a/EnvelopeGenerator.Application/Interfaces/Repositories/IEnvelopeRepository.cs +++ b/EnvelopeGenerator.Application/Interfaces/Repositories/IEnvelopeRepository.cs @@ -1,4 +1,5 @@ using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Domain; using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.Application.Interfaces.Repositories; @@ -38,5 +39,5 @@ public interface IEnvelopeRepository : ICRUDRepository /// /// /// - Task> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses); + Task> ReadByUserAsync(int userId, Constants.EnvelopeStatus? min_status = null, Constants.EnvelopeStatus? max_status = null, params Constants.EnvelopeStatus[] ignore_statuses); } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Interfaces/Services/IEnvelopeReceiverService.cs b/EnvelopeGenerator.Application/Interfaces/Services/IEnvelopeReceiverService.cs index 77941538..7829668a 100644 --- a/EnvelopeGenerator.Application/Interfaces/Services/IEnvelopeReceiverService.cs +++ b/EnvelopeGenerator.Application/Interfaces/Services/IEnvelopeReceiverService.cs @@ -6,6 +6,7 @@ using EnvelopeGenerator.Application.Dto.Messaging; using EnvelopeGenerator.Application.Envelopes; using EnvelopeGenerator.Application.Envelopes.Queries; using EnvelopeGenerator.Application.Receivers.Queries; +using EnvelopeGenerator.Domain; using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.Application.Interfaces.Services; @@ -121,7 +122,7 @@ public interface IEnvelopeReceiverService : IBasicCRUDService /// /// - Task>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, ReadEnvelopeQuery? envelopeQuery = null, ReadReceiverQuery? receiverQuery = null, params int[] ignore_statuses); + Task>> ReadByUsernameAsync(string username, Constants.EnvelopeStatus? min_status = null, Constants.EnvelopeStatus? max_status = null, ReadEnvelopeQuery? envelopeQuery = null, ReadReceiverQuery? receiverQuery = null, params Constants.EnvelopeStatus[] ignore_statuses); /// /// diff --git a/EnvelopeGenerator.Application/Interfaces/Services/IEnvelopeService.cs b/EnvelopeGenerator.Application/Interfaces/Services/IEnvelopeService.cs index a97c3075..ab49de57 100644 --- a/EnvelopeGenerator.Application/Interfaces/Services/IEnvelopeService.cs +++ b/EnvelopeGenerator.Application/Interfaces/Services/IEnvelopeService.cs @@ -1,6 +1,7 @@ using DigitalData.Core.Abstraction.Application; using DigitalData.Core.Abstraction.Application.DTO; using EnvelopeGenerator.Application.Dto; +using EnvelopeGenerator.Domain; using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.Application.Interfaces.Services; @@ -40,5 +41,5 @@ public interface IEnvelopeService : IBasicCRUDService /// /// - Task>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses); + Task>> ReadByUserAsync(int userId, Constants.EnvelopeStatus? min_status = null, Constants.EnvelopeStatus? max_status = null, params Constants.EnvelopeStatus[] ignore_statuses); } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs b/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs index 2c367b17..f55537bf 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs @@ -13,6 +13,8 @@ using EnvelopeGenerator.Application.Interfaces.Services; using EnvelopeGenerator.Application.Envelopes; using EnvelopeGenerator.Application.Envelopes.Queries; using EnvelopeGenerator.Application.Receivers.Queries; +using System.Reflection.Metadata; +using EnvelopeGenerator.Domain; namespace EnvelopeGenerator.Application.Services; @@ -237,7 +239,7 @@ public class EnvelopeReceiverService : BasicCRUDService /// /// - public async Task>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, ReadEnvelopeQuery? envelopeQuery = null, ReadReceiverQuery? receiverQuery = null, params int[] ignore_statuses) + public async Task>> ReadByUsernameAsync(string username, Constants.EnvelopeStatus? min_status = null, Constants.EnvelopeStatus? max_status = null, ReadEnvelopeQuery? envelopeQuery = null, ReadReceiverQuery? receiverQuery = null, params Constants.EnvelopeStatus[] ignore_statuses) { var er_list = await _repository.ReadByUsernameAsync(username: username, min_status: min_status, max_status: max_status, ignore_statuses: ignore_statuses); @@ -247,7 +249,7 @@ public class EnvelopeReceiverService : BasicCRUDService er.Envelope?.Uuid == uuid); - if (envelopeQuery?.StatusQ is int status) + if (envelopeQuery?.StatusQ?.Status?.FirstOrDefault() is Constants.EnvelopeStatus status) er_list = er_list.Where(er => er.Envelope?.Status == status); if(receiverQuery?.Id is int id) diff --git a/EnvelopeGenerator.Application/Services/EnvelopeService.cs b/EnvelopeGenerator.Application/Services/EnvelopeService.cs index 4f0501eb..594486e8 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeService.cs @@ -5,6 +5,9 @@ using EnvelopeGenerator.Application.Interfaces.Services; using EnvelopeGenerator.Application.Dto; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Application.Interfaces.Repositories; +using EnvelopeGenerator.Application.Envelopes.Queries; +using System.Reflection.Metadata; +using EnvelopeGenerator.Domain; namespace EnvelopeGenerator.Application.Services; @@ -67,7 +70,7 @@ public class EnvelopeService : BasicCRUDService /// /// - public async Task>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses) + public async Task>> ReadByUserAsync(int userId, Constants.EnvelopeStatus? min_status = null, Constants.EnvelopeStatus? max_status = null, params Constants.EnvelopeStatus[] ignore_statuses) { var users = await _repository.ReadByUserAsync(userId: userId, min_status: min_status, max_status: max_status, ignore_statuses: ignore_statuses); var readDto = _mapper.Map>(users); diff --git a/EnvelopeGenerator.Domain/Entities/Envelope.cs b/EnvelopeGenerator.Domain/Entities/Envelope.cs index 5dafbec9..77648690 100644 --- a/EnvelopeGenerator.Domain/Entities/Envelope.cs +++ b/EnvelopeGenerator.Domain/Entities/Envelope.cs @@ -22,7 +22,7 @@ public class Envelope // TODO: * Check the Form App and remove the default value #if NETFRAMEWORK Id = 0; - Status = (int)Constants.EnvelopeStatus.EnvelopeCreated; + Status = Constants.EnvelopeStatus.EnvelopeCreated; Uuid = Guid.NewGuid().ToString(); Message = My.Resources.Envelope.Please_read_and_sign_this_document; Title= string.Empty; @@ -153,7 +153,7 @@ public class Envelope public string CURRENT_WORK_APP { get; set; } = "signFLOW GUI"; [NotMapped] - public bool IsAlreadySent => Status > (int)Constants.EnvelopeStatus.EnvelopeSaved; + public bool IsAlreadySent => Status > Constants.EnvelopeStatus.EnvelopeSaved; #endif public List Documents { get; set; } diff --git a/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeRepository.cs index dabdcfbe..03f7e0ad 100644 --- a/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeRepository.cs @@ -2,6 +2,7 @@ using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Application.Interfaces.Repositories; using Microsoft.EntityFrameworkCore; +using EnvelopeGenerator.Domain; namespace EnvelopeGenerator.Infrastructure.Repositories; @@ -47,7 +48,7 @@ public class EnvelopeRepository : CRUDRepository, IE return await query.FirstOrDefaultAsync(); } - public async Task> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses) + public async Task> ReadByUserAsync(int userId, Constants.EnvelopeStatus? min_status = null, Constants.EnvelopeStatus? max_status = null, params Constants.EnvelopeStatus[] ignore_statuses) { var query = _dbSet.AsNoTracking().Where(e => e.UserId == userId); diff --git a/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs index 00c481db..024c02c6 100644 --- a/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs @@ -3,6 +3,7 @@ using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Application.Interfaces.Repositories; using Microsoft.EntityFrameworkCore; using EnvelopeGenerator.Application.Exceptions; +using EnvelopeGenerator.Domain; namespace EnvelopeGenerator.Infrastructure.Repositories; @@ -79,7 +80,7 @@ public class EnvelopeReceiverRepository : CRUDRepository er.AccessCode) .FirstOrDefaultAsync(); - public async Task> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses) + public async Task> ReadByUsernameAsync(string username, Constants.EnvelopeStatus? min_status = null, Constants.EnvelopeStatus? max_status = null, params Constants.EnvelopeStatus[] ignore_statuses) { var query = _dbSet.AsNoTracking().Where(er => er.Envelope!.User!.Username == username);