From 803f33fe001d71c4607a607685f9790fc3987560 Mon Sep 17 00:00:00 2001 From: Thomas Ryan Date: Wed, 2 Aug 2023 15:24:54 -0700 Subject: [PATCH] Added the ability to suppress the sending of confirmation emails for quotes and orders in support of #373. --- NumberSearch.DataAccess/Models/Order.cs | 1 + NumberSearch.Mvc/Controllers/CartController.cs | 13 ++++++++----- NumberSearch.Mvc/Controllers/LookupController.cs | 2 -- NumberSearch.Mvc/Views/Cart/Order.cshtml | 8 ++++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/NumberSearch.DataAccess/Models/Order.cs b/NumberSearch.DataAccess/Models/Order.cs index 70e99cb6..f8021721 100644 --- a/NumberSearch.DataAccess/Models/Order.cs +++ b/NumberSearch.DataAccess/Models/Order.cs @@ -28,6 +28,7 @@ public class Order public string BillingInvoiceId { get; set; } = string.Empty; public decimal SalesTax { get; set; } public bool Quote { get; set; } + public bool NoEmail { get; set; } public string BillingInvoiceReoccuringId { get; set; } = string.Empty; public string SalesEmail { get; set; } = string.Empty; public bool BackgroundWorkCompleted { get; set; } diff --git a/NumberSearch.Mvc/Controllers/CartController.cs b/NumberSearch.Mvc/Controllers/CartController.cs index 18cca5e1..824adffb 100644 --- a/NumberSearch.Mvc/Controllers/CartController.cs +++ b/NumberSearch.Mvc/Controllers/CartController.cs @@ -391,7 +391,9 @@ public async Task SubmitAsync(Order order) // Send a confirmation email. if (submittedOrder) { + bool NoEmail = order.NoEmail; order = await Order.GetByIdAsync(order.OrderId, _postgresql).ConfigureAwait(false); + order.NoEmail = NoEmail; // Submit the number orders and track the total cost. var onetimeItems = new List(); @@ -1427,19 +1429,20 @@ Accelerate Networks confirmationEmail.CalendarInvite = icalString; } - // If there are notes on the order don't send out any emails to the customer. - if (string.IsNullOrWhiteSpace(order.CustomerNotes)) + // Suppress the confirmation emails. + if (order.NoEmail) { - // Queue up the confirmation email. confirmationEmail.Completed = false; + confirmationEmail.PrimaryEmailAddress = string.IsNullOrWhiteSpace(order.SalesEmail) ? "support@acceleratenetworks.com" : order.SalesEmail; var checkSave = await confirmationEmail.PostAsync(_postgresql).ConfigureAwait(false); + Log.Information($"Suppressed sending out the confirmation emails for {order.OrderId}."); } else { + // Queue up the confirmation email. confirmationEmail.Completed = false; - confirmationEmail.PrimaryEmailAddress = string.IsNullOrWhiteSpace(order.SalesEmail) ? "support@acceleratenetworks.com" : order.SalesEmail; var checkSave = await confirmationEmail.PostAsync(_postgresql).ConfigureAwait(false); - Log.Information($"Skipped sending out the confirmation emails for {order.OrderId} due to customer notes."); + Log.Information($"Sent out the confirmation emails for {order.OrderId}."); } // Allow the background work to commence. diff --git a/NumberSearch.Mvc/Controllers/LookupController.cs b/NumberSearch.Mvc/Controllers/LookupController.cs index 7111253d..7d360517 100644 --- a/NumberSearch.Mvc/Controllers/LookupController.cs +++ b/NumberSearch.Mvc/Controllers/LookupController.cs @@ -14,8 +14,6 @@ using System.Text; using System.Threading.Tasks; -using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext; - namespace NumberSearch.Mvc.Controllers { [ApiExplorerSettings(IgnoreApi = true)] diff --git a/NumberSearch.Mvc/Views/Cart/Order.cshtml b/NumberSearch.Mvc/Views/Cart/Order.cshtml index ccc67eed..ad6f5b1b 100644 --- a/NumberSearch.Mvc/Views/Cart/Order.cshtml +++ b/NumberSearch.Mvc/Views/Cart/Order.cshtml @@ -799,6 +799,14 @@ +
+
+ + +
+