From 8a4d3ff6f9411e665481ffaff599de2ab8f85a54 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 26 Aug 2025 22:34:54 +0200 Subject: [PATCH] refactor(SaveDocStatusCommand): simplify repository filtering in SaveDocStatusCommandHandler - Replaced explicit envelope and receiver expression filters with a single `.Where(request)` call. - Removed redundant checks for null and empty values in handler. - Updated using statements to include `EnvelopeGenerator.Application.Extensions`. - Maintains the same functionality while reducing code complexity. --- .../Commands/SaveDocStatusCommand.cs | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs b/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs index 28a24b80..85874a56 100644 --- a/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs +++ b/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs @@ -1,9 +1,8 @@ using DigitalData.Core.Abstraction.Application.Repository; -using DigitalData.Core.Exceptions; using EnvelopeGenerator.Domain.Entities; using MediatR; using Microsoft.EntityFrameworkCore; -using System.Linq.Expressions; +using EnvelopeGenerator.Application.Extensions; namespace EnvelopeGenerator.Application.DocStatus.Commands; @@ -60,30 +59,13 @@ public class SaveDocStatusCommandHandler : IRequestHandler public async Task Handle(SaveDocStatusCommand request, CancellationToken cancel) { - // envelope filter - Expression>? eExp = - request.Envelope.Id is not null - ? ds => ds.EnvelopeId == request.Envelope.Id - : !string.IsNullOrWhiteSpace(request.Envelope.Uuid) - ? ds => ds.Envelope.Uuid == request.Envelope.Uuid - : throw new BadRequestException(); - - // receiver filter - Expression>? rExp = - request.Receiver.Id is not null - ? ds => ds.ReceiverId == request.Receiver.Id - : request.Receiver.EmailAddress is not null - ? ds => ds.Receiver.EmailAddress == request.Receiver.EmailAddress - : !string.IsNullOrWhiteSpace(request.Receiver.Signature) ? ds => ds.Receiver.Signature == request.Receiver.Signature - : throw new BadRequestException(); - // ceck if exists - bool isExists = await _repo.ReadOnly().Where(eExp).Where(rExp).AnyAsync(cancel); + bool isExists = await _repo.ReadOnly().Where(request).AnyAsync(cancel); if (isExists) { var uReq = request.To(); - await _repo.UpdateAsync(uReq, q => q.Where(eExp).Where(rExp), cancel); + await _repo.UpdateAsync(uReq, q => q.Where(request), cancel); } else { @@ -91,7 +73,7 @@ public class SaveDocStatusCommandHandler : IRequestHandler