refactor(SendEmailBehavior): update to add history recors when request is not debug

This commit is contained in:
tekh 2025-11-12 15:35:23 +01:00
parent cbe2acc37d
commit d442ad0ce0

View File

@ -43,7 +43,7 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
if (mailToCreator is not null && mailToCreator != (int)FinalEmailType.No) if (mailToCreator is not null && mailToCreator != (int)FinalEmailType.No)
{ {
_logger.LogDebug("Sending email to creator ..."); _logger.LogDebug("Sending email to creator ...");
await SendFinalEmailToCreatorAsync(request.Envelope, cancel); // , pAttachment await SendFinalEmailToCreatorAsync(request, cancel); // , pAttachment
} }
else else
{ {
@ -54,7 +54,7 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
if (mailToReceivers != (int)FinalEmailType.No) if (mailToReceivers != (int)FinalEmailType.No)
{ {
_logger.LogDebug("Sending emails to receivers..."); _logger.LogDebug("Sending emails to receivers...");
await SendFinalEmailToReceiversAsync(request.Envelope, cancel); // , pAttachment await SendFinalEmailToReceiversAsync(request, cancel); // , pAttachment
} }
else else
{ {
@ -65,9 +65,9 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
return docResult; return docResult;
} }
private async Task SendFinalEmailToCreatorAsync(Envelope envelope, CancellationToken cancel) //, string pAttachment private async Task SendFinalEmailToCreatorAsync(BurnPdfCommand request, CancellationToken cancel) //, string pAttachment
{ {
bool oIncludeAttachment = SendFinalEmailWithAttachment(envelope.FinalEmailToCreator); bool oIncludeAttachment = SendFinalEmailWithAttachment(request.Envelope!.FinalEmailToCreator);
// string oAttachment = string.Empty; // string oAttachment = string.Empty;
_logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment); _logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment);
@ -76,17 +76,18 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
// oAttachment = pAttachment; // oAttachment = pAttachment;
} }
await _sender.Send(new CreateHistoryCommand() if (!request.Debug)
{ await _sender.Send(new CreateHistoryCommand()
EnvelopeId = envelope.Id, {
Status = EnvelopeStatus.MessageCompletionSent, EnvelopeId = request.Envelope!.Id,
UserReference = envelope.User.Email, Status = EnvelopeStatus.MessageCompletionSent,
}, cancel); UserReference = request.Envelope.User.Email,
}, cancel);
} }
private async Task SendFinalEmailToReceiversAsync(Envelope envelope, CancellationToken cancel) //, string pAttachment private async Task SendFinalEmailToReceiversAsync(BurnPdfCommand request, CancellationToken cancel) //, string pAttachment
{ {
bool oIncludeAttachment = SendFinalEmailWithAttachment(envelope.FinalEmailToReceivers); bool oIncludeAttachment = SendFinalEmailWithAttachment(request.Envelope!.FinalEmailToReceivers);
// string oAttachment = string.Empty; // string oAttachment = string.Empty;
_logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment); _logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment);
@ -96,11 +97,12 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
} }
// TODO update CreateHistoryCommand to be able to create all records together // TODO update CreateHistoryCommand to be able to create all records together
await Task.WhenAll(envelope.EnvelopeReceivers!.Select(receiver => _sender.Send(new CreateHistoryCommand() if (!request.Debug)
{ await Task.WhenAll(request.Envelope!.EnvelopeReceivers!.Select(receiver => _sender.Send(new CreateHistoryCommand()
EnvelopeId = envelope.Id, {
Status = EnvelopeStatus.MessageCompletionSent, EnvelopeId = request.Envelope!.Id,
UserReference = receiver.Receiver!.EmailAddress, Status = EnvelopeStatus.MessageCompletionSent,
}, cancel))); UserReference = receiver.Receiver!.EmailAddress,
}, cancel)));
} }
} }