From fac5419589a6da4cff7d1efca49ee0d11303fd9e Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 12 Nov 2025 15:44:37 +0100 Subject: [PATCH] refactor: simplify email sending logic and remove debug checks - Removed unused `EnvelopeGenerator.Domain.Entities` import. - Changed `SendFinalEmailWithAttachment` calls to explicitly cast envelope email type to `int`. - Removed `Debug` conditional checks around history creation; history commands are now always sent. - Made `SendFinalEmailWithAttachment` a static method for clarity. --- .../Pdf/Behaviors/SendEmailBehavior.cs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/EnvelopeGenerator.Application/Pdf/Behaviors/SendEmailBehavior.cs b/EnvelopeGenerator.Application/Pdf/Behaviors/SendEmailBehavior.cs index 505753ea..42948608 100644 --- a/EnvelopeGenerator.Application/Pdf/Behaviors/SendEmailBehavior.cs +++ b/EnvelopeGenerator.Application/Pdf/Behaviors/SendEmailBehavior.cs @@ -1,6 +1,5 @@ using EnvelopeGenerator.Application.Histories.Commands; using EnvelopeGenerator.Domain.Constants; -using EnvelopeGenerator.Domain.Entities; using MediatR; using Microsoft.Extensions.Logging; @@ -67,7 +66,7 @@ public class SendEmailBehavior : IPipelineBehavior private async Task SendFinalEmailToCreatorAsync(BurnPdfCommand request, CancellationToken cancel) //, string pAttachment { - bool oIncludeAttachment = SendFinalEmailWithAttachment(request.Envelope!.FinalEmailToCreator); + bool oIncludeAttachment = SendFinalEmailWithAttachment((int)request.Envelope!.FinalEmailToCreator!); // string oAttachment = string.Empty; _logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment); @@ -76,18 +75,17 @@ public class SendEmailBehavior : IPipelineBehavior // oAttachment = pAttachment; } - if (!request.Debug) - await _sender.Send(new CreateHistoryCommand() - { - EnvelopeId = request.Envelope!.Id, - Status = EnvelopeStatus.MessageCompletionSent, - UserReference = request.Envelope.User.Email, - }, cancel); + await _sender.Send(new CreateHistoryCommand() + { + EnvelopeId = request.Envelope!.Id, + Status = EnvelopeStatus.MessageCompletionSent, + UserReference = request.Envelope.User.Email, + }, cancel); } private async Task SendFinalEmailToReceiversAsync(BurnPdfCommand request, CancellationToken cancel) //, string pAttachment { - bool oIncludeAttachment = SendFinalEmailWithAttachment(request.Envelope!.FinalEmailToReceivers); + bool oIncludeAttachment = SendFinalEmailWithAttachment((int)request.Envelope!.FinalEmailToReceivers!); // string oAttachment = string.Empty; _logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment); @@ -97,12 +95,13 @@ public class SendEmailBehavior : IPipelineBehavior } // TODO update CreateHistoryCommand to be able to create all records together - if (!request.Debug) - await Task.WhenAll(request.Envelope!.EnvelopeReceivers!.Select(receiver => _sender.Send(new CreateHistoryCommand() - { - EnvelopeId = request.Envelope!.Id, - Status = EnvelopeStatus.MessageCompletionSent, - UserReference = receiver.Receiver!.EmailAddress, - }, cancel))); + await Task.WhenAll(request.Envelope!.EnvelopeReceivers!.Select(receiver => _sender.Send(new CreateHistoryCommand() + { + EnvelopeId = request.Envelope!.Id, + Status = EnvelopeStatus.MessageCompletionSent, + UserReference = receiver.Receiver!.EmailAddress, + }, cancel))); } + + private static bool SendFinalEmailWithAttachment(int type) => type == (int)FinalEmailType.YesWithAttachment; } \ No newline at end of file