Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Extend Queued Email entity - add Reference Object and key, admin panel - add a new tab on the order - Notifications
KrzysztofPajakc6fcb34c0156
diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/OrderStatusCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/OrderStatusCommandHandler.csindex 88ec13bd2..a4610873c 100644--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/OrderStatusCommandHandler.cs+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/OrderStatusCommandHandler.cs@@ -3,7 +3,6 @@ using Grand.Business.Checkout.Interfaces.Orders;using Grand.Business.Common.Interfaces.Pdf;using Grand.Business.Customers.Interfaces;using Grand.Business.Messages.Interfaces;-using Grand.Domain.Customers;using Grand.Domain.Orders;using MediatR;using System;@@ -58,8 +57,7 @@ namespace Grand.Business.Checkout.Commands.Handlers.Ordersawait _orderService.UpdateOrder(request.Order);//order notes, notifications- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = string.Format("Order status has been changed to {0}", request.Os.ToString()),DisplayToCustomer = false,OrderId = request.Order.Id,@@ -82,19 +80,9 @@ namespace Grand.Business.Checkout.Commands.Handlers.Ordersvar orderCompletedAttachments = _orderSettings.AttachPdfInvoiceToOrderCompletedEmail && _orderSettings.AttachPdfInvoiceToBinary ?new List<string> { await _pdfService.SaveOrderToBinary(request.Order, "") } : new List<string>();- int orderCompletedCustomerNotificationQueuedEmailId = await _messageProviderService+ await _messageProviderService.SendOrderCompletedCustomerMessage(request.Order, customer, request.Order.CustomerLanguageId, orderCompletedAttachmentFilePath,orderCompletedAttachmentFileName, orderCompletedAttachments);- if (orderCompletedCustomerNotificationQueuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "\"Order completed\" email (to customer) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = request.Order.Id,- });- }}if (prevOrderStatus != (int)OrderStatusSystem.Cancelled &&@@ -102,17 +90,8 @@ namespace Grand.Business.Checkout.Commands.Handlers.Orders&& request.NotifyCustomer){//notification customer- int orderCancelledCustomerNotificationQueuedEmailId = await _messageProviderService.SendOrderCancelledCustomerMessage(request.Order, customer, request.Order.CustomerLanguageId);- if (orderCancelledCustomerNotificationQueuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "\"Order cancelled\" email (to customer) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = request.Order.Id,- });- }+ await _messageProviderService.SendOrderCancelledCustomerMessage(request.Order, customer, request.Order.CustomerLanguageId);+//notification for vendorawait VendorNotification(request.Order);}@@ -125,8 +104,7 @@ namespace Grand.Business.Checkout.Commands.Handlers.Ordersvar orderCancelledStoreOwnerNotificationQueuedEmailId = await _messageProviderService.SendOrderCancelledStoreOwnerMessage(request.Order, customer, request.Order.CustomerLanguageId);if (orderCancelledStoreOwnerNotificationQueuedEmailId > 0){- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = "\"Order cancelled\" by customer.",DisplayToCustomer = true,CreatedOnUtc = DateTime.UtcNow,diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PartiallyRefundCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PartiallyRefundCommandHandler.csindex 5ae559756..e461a83a1 100644--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PartiallyRefundCommandHandler.cs+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PartiallyRefundCommandHandler.cs@@ -8,7 +8,6 @@ using Grand.Business.Common.Interfaces.Logging;using Grand.Business.Messages.Interfaces;using Grand.Domain.Localization;using Grand.Domain.Logging;-using Grand.Domain.Orders;using Grand.SharedKernel;using MediatR;using System;@@ -92,30 +91,10 @@ namespace Grand.Business.Checkout.Commands.Handlers.Ordersawait _mediator.Send(new CheckOrderStatusCommand() { Order = order });//notifications- var orderRefundedStoreOwnerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, amountToRefund, _languageSettings.DefaultAdminLanguageId);- if (orderRefundedStoreOwnerNotificationQueuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "Order refunded email (to store owner) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });- }--- var orderRefundedCustomerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedCustomerMessage(order, amountToRefund, order.CustomerLanguageId);- if (orderRefundedCustomerNotificationQueuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "Order refunded email (to customer) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });- }+ await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, amountToRefund, _languageSettings.DefaultAdminLanguageId);++ await _messageProviderService.SendOrderRefundedCustomerMessage(order, amountToRefund, order.CustomerLanguageId);+}//raise eventawait _mediator.Publish(new PaymentTransactionRefundedEvent(paymentTransaction, amountToRefund));diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.csindex 09d0e77d8..9fc01dfa4 100644--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs@@ -1141,19 +1141,8 @@ namespace Grand.Business.Checkout.Commands.Handlers.Orders}//send email notifications- int orderPlacedStoreOwnerNotificationQueuedEmailId = await messageProviderService.SendOrderPlacedStoreOwnerMessage(order, customer, languageSettings.DefaultAdminLanguageId);- if (orderPlacedStoreOwnerNotificationQueuedEmailId > 0)- {- await orderService.InsertOrderNote(new OrderNote- {- Note = "Order placed email (to store owner) has been queued",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,-- });- }-+ await messageProviderService.SendOrderPlacedStoreOwnerMessage(order, customer, languageSettings.DefaultAdminLanguageId);+string orderPlacedAttachmentFilePath = string.Empty, orderPlacedAttachmentFileName = string.Empty;var orderPlacedAttachments = new List<string>();@@ -1171,36 +1160,15 @@ namespace Grand.Business.Checkout.Commands.Handlers.Orders_logger.Error($"Error - order placed attachment file {order.OrderNumber}", ex);}- int orderPlacedCustomerNotificationQueuedEmailId = await messageProviderService+ await messageProviderService.SendOrderPlacedCustomerMessage(order, customer, order.CustomerLanguageId, orderPlacedAttachmentFilePath, orderPlacedAttachmentFileName, orderPlacedAttachments);- if (orderPlacedCustomerNotificationQueuedEmailId > 0)- {- await orderService.InsertOrderNote(new OrderNote- {- Note = "Order placed email (to customer) has been queued",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,-- });- }if (order.OrderItems.Any(x => !string.IsNullOrEmpty(x.VendorId))){var vendors = await mediator.Send(new GetVendorsInOrderQuery() { Order = order });foreach (var vendor in vendors){- int orderPlacedVendorNotificationQueuedEmailId = await messageProviderService.SendOrderPlacedVendorMessage(order, customer, vendor, languageSettings.DefaultAdminLanguageId);- if (orderPlacedVendorNotificationQueuedEmailId > 0)- {- await orderService.InsertOrderNote(new OrderNote- {- Note = "Order placed email (to vendor) has been queued",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });- }+ await messageProviderService.SendOrderPlacedVendorMessage(order, customer, vendor, languageSettings.DefaultAdminLanguageId);}}}diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/RefundCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/RefundCommandHandler.csindex 286181cf3..bd7f9613f 100644--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/RefundCommandHandler.cs+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/RefundCommandHandler.cs@@ -7,7 +7,6 @@ using Grand.Business.Common.Interfaces.Logging;using Grand.Business.Messages.Interfaces;using Grand.Domain.Localization;using Grand.Domain.Logging;-using Grand.Domain.Orders;using MediatR;using System;using System.Collections.Generic;@@ -82,31 +81,11 @@ namespace Grand.Business.Checkout.Commands.Handlers.Orders//check order statusawait _mediator.Send(new CheckOrderStatusCommand() { Order = order });- //notifications- var orderRefundedStoreOwnerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, request.AmountToRefund, _languageSettings.DefaultAdminLanguageId);- if (orderRefundedStoreOwnerNotificationQueuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "Order refunded email (to store owner) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });- }-- //notifications- var orderRefundedCustomerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedCustomerMessage(order, request.AmountToRefund, order.CustomerLanguageId);- if (orderRefundedCustomerNotificationQueuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "Order refunded email (to customer) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });- }+ //notifications for store owner+ await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, request.AmountToRefund, _languageSettings.DefaultAdminLanguageId);++ //notifications for customer+ await _messageProviderService.SendOrderRefundedCustomerMessage(order, request.AmountToRefund, order.CustomerLanguageId);//raise eventawait _mediator.Publish(new PaymentTransactionRefundedEvent(paymentTransaction, request.AmountToRefund));diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/RefundOfflineCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/RefundOfflineCommandHandler.csindex d3ec1f498..e2779e076 100644--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/RefundOfflineCommandHandler.cs+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/RefundOfflineCommandHandler.cs@@ -5,7 +5,6 @@ using Grand.Business.Checkout.Interfaces.Payments;using Grand.Business.Checkout.Queries.Models.Orders;using Grand.Business.Messages.Interfaces;using Grand.Domain.Localization;-using Grand.Domain.Orders;using Grand.Domain.Payments;using Grand.SharedKernel;using MediatR;@@ -24,10 +23,10 @@ namespace Grand.Business.Checkout.Commands.Handlers.Ordersprivate readonly LanguageSettings _languageSettings;public RefundOfflineCommandHandler(- IMediator mediator,+ IMediator mediator,IOrderService orderService,IPaymentTransactionService paymentTransactionService,- IMessageProviderService messageProviderService,+ IMessageProviderService messageProviderService,LanguageSettings languageSettings){_mediator = mediator;@@ -72,32 +71,11 @@ namespace Grand.Business.Checkout.Commands.Handlers.Orders//check order statusawait _mediator.Send(new CheckOrderStatusCommand() { Order = order });- //notifications- var orderRefundedStoreOwnerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, amountToRefund, _languageSettings.DefaultAdminLanguageId);- if (orderRefundedStoreOwnerNotificationQueuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "Order refunded email (to store owner) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });-- }--- var orderRefundedCustomerNotificationQueuedEmailId = await _messageProviderService.SendOrderRefundedCustomerMessage(order, amountToRefund, order.CustomerLanguageId);- if (orderRefundedCustomerNotificationQueuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "\"Order refunded\" email (to customer) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });- }+ //notifications for store owner+ await _messageProviderService.SendOrderRefundedStoreOwnerMessage(order, amountToRefund, _languageSettings.DefaultAdminLanguageId);++ //notifications for customer+ await _messageProviderService.SendOrderRefundedCustomerMessage(order, amountToRefund, order.CustomerLanguageId);//raise eventawait _mediator.Publish(new PaymentTransactionRefundedEvent(paymentTransaction, amountToRefund));diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Shipping/DeliveryCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Shipping/DeliveryCommandHandler.csindex 4a702de6c..311d755ed 100644--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Shipping/DeliveryCommandHandler.cs+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Shipping/DeliveryCommandHandler.cs@@ -1,5 +1,4 @@-using Grand.Business.Catalog.Interfaces.Products;-using Grand.Business.Checkout.Commands.Models.Orders;+using Grand.Business.Checkout.Commands.Models.Orders;using Grand.Business.Checkout.Commands.Models.Shipping;using Grand.Business.Checkout.Extensions;using Grand.Business.Checkout.Interfaces.Orders;@@ -60,8 +59,7 @@ namespace Grand.Business.Checkout.Commands.Handlers.Shipping}//add a note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = $"Shipment #{request.Shipment.ShipmentNumber} has been delivered",DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,@@ -70,17 +68,7 @@ namespace Grand.Business.Checkout.Commands.Handlers.Shippingif (request.NotifyCustomer){//send email notification- int queuedEmailId = await _messageProviderService.SendShipmentDeliveredCustomerMessage(request.Shipment, order);- if (queuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "\"Delivered\" email (to customer) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });- }+ await _messageProviderService.SendShipmentDeliveredCustomerMessage(request.Shipment, order);}//eventawait _mediator.PublishShipmentDelivered(request.Shipment);diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Shipping/ShipCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Shipping/ShipCommandHandler.csindex 5b49360c1..c65e17cce 100644--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Shipping/ShipCommandHandler.cs+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Shipping/ShipCommandHandler.cs@@ -1,5 +1,4 @@-using Grand.Business.Catalog.Interfaces.Products;-using Grand.Business.Checkout.Commands.Models.Orders;+using Grand.Business.Checkout.Commands.Models.Orders;using Grand.Business.Checkout.Commands.Models.Shipping;using Grand.Business.Checkout.Extensions;using Grand.Business.Checkout.Interfaces.Orders;@@ -20,23 +19,17 @@ namespace Grand.Business.Checkout.Commands.Handlers.Shippingprivate readonly IMediator _mediator;private readonly IOrderService _orderService;private readonly IShipmentService _shipmentService;- private readonly IProductService _productService;- private readonly IInventoryManageService _inventoryManageService;private readonly IMessageProviderService _messageProviderService;public ShipCommandHandler(IMediator mediator,IOrderService orderService,IShipmentService shipmentService,- IProductService productService,- IInventoryManageService inventoryManageService,IMessageProviderService messageProviderService){_mediator = mediator;_orderService = orderService;_shipmentService = shipmentService;- _productService = productService;- _inventoryManageService = inventoryManageService;_messageProviderService = messageProviderService;}@@ -69,8 +62,7 @@ namespace Grand.Business.Checkout.Commands.Handlers.Shippingawait _orderService.UpdateOrder(order);//add a note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = $"Shipment #{request.Shipment.ShipmentNumber} has been sent",DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,@@ -80,17 +72,7 @@ namespace Grand.Business.Checkout.Commands.Handlers.Shippingif (request.NotifyCustomer){//notify customer- int queuedEmailId = await _messageProviderService.SendShipmentSentCustomerMessage(request.Shipment, order);- if (queuedEmailId > 0)- {- await _orderService.InsertOrderNote(new OrderNote- {- Note = "\"Shipped\" email (to customer) has been queued.",- DisplayToCustomer = false,- CreatedOnUtc = DateTime.UtcNow,- OrderId = order.Id,- });- }+ await _messageProviderService.SendShipmentSentCustomerMessage(request.Shipment, order);}//eventawait _mediator.PublishShipmentSent(request.Shipment);diff --git a/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs b/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.csindex 7fb8abb52..59ab92ad7 100644--- a/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs+++ b/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs@@ -354,6 +354,8 @@ namespace Grand.Business.Marketing.Services.Campaignsemail.Body = body;email.CreatedOnUtc = DateTime.UtcNow;email.EmailAccountId = emailAccount.Id;+ email.Reference = Domain.Common.Reference.Campaign;+ email.ObjectId = campaign.Id;await _queuedEmailService.InsertQueuedEmail(email);await InsertCampaignHistory(new CampaignHistory() { CampaignId = campaign.Id, CustomerId = subscription.CustomerId, Email = subscription.Email, CreatedDateUtc = DateTime.UtcNow, StoreId = campaign.StoreId });diff --git a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerReminderService.cs b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerReminderService.csindex 87b8e44cd..216f114b5 100644--- a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerReminderService.cs+++ b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerReminderService.cs@@ -129,6 +129,8 @@ namespace Grand.Business.Marketing.Services.Customersemail.AttachedDownloads = null;email.CreatedOnUtc = DateTime.UtcNow;email.EmailAccountId = emailAccount.Id;+ email.Reference = Reference.CustomerReminder;+ email.ObjectId = customerReminder.Id;await _queuedEmailService.InsertQueuedEmail(email);//activity log@@ -199,6 +201,8 @@ namespace Grand.Business.Marketing.Services.CustomersAttachedDownloads = null,CreatedOnUtc = DateTime.UtcNow,EmailAccountId = emailAccount.Id,+ Reference = Reference.CustomerReminder,+ ObjectId = customerReminder.Id,};await _queuedEmailService.InsertQueuedEmail(email);diff --git a/src/Business/Grand.Business.Messages/Interfaces/IMessageProviderService.cs b/src/Business/Grand.Business.Messages/Interfaces/IMessageProviderService.csindex bd7b47e88..828bcb949 100644--- a/src/Business/Grand.Business.Messages/Interfaces/IMessageProviderService.cs+++ b/src/Business/Grand.Business.Messages/Interfaces/IMessageProviderService.cs@@ -563,6 +563,8 @@ namespace Grand.Business.Messages.Interfaces/// <param name="fromEmail">Sender email. If specified, then it overrides passed "emailAccount" details</param>/// <param name="fromName">Sender name. If specified, then it overrides passed "emailAccount" details</param>/// <param name="subject">Subject. If specified, then it overrides subject of a message template</param>+ /// <param name="reference">Reference object</param>+ /// <param name="objectId">Reference object ident</param>/// <returns>Queued email identifier</returns>Task<int> SendNotification(MessageTemplate messageTemplate,EmailAccount emailAccount, string languageId, LiquidObject liquidObject,@@ -570,7 +572,8 @@ namespace Grand.Business.Messages.Interfacesstring attachmentFilePath = null, string attachmentFileName = null,IEnumerable<string> attachedDownloads = null,string replyToEmailAddress = null, string replyToName = null,- string fromEmail = null, string fromName = null, string subject = null);+ string fromEmail = null, string fromName = null, string subject = null,+ Reference reference = Reference.None, string objectId = "");#endregion}diff --git a/src/Business/Grand.Business.Messages/Interfaces/IQueuedEmailService.cs b/src/Business/Grand.Business.Messages/Interfaces/IQueuedEmailService.csindex 3cd924015..0d4a90aed 100644--- a/src/Business/Grand.Business.Messages/Interfaces/IQueuedEmailService.cs+++ b/src/Business/Grand.Business.Messages/Interfaces/IQueuedEmailService.cs@@ -56,14 +56,18 @@ namespace Grand.Business.Messages.Interfaces/// <param name="createdToUtc">Created date to (UTC); null to load all records</param>/// <param name="loadNotSentItemsOnly">A value indicating whether to load only not sent emails</param>/// <param name="maxSendTries">Maximum send tries</param>+ /// <param name="loadOnlyItemsToBeSent">Load only items to be sent</param>/// <param name="loadNewest">A value indicating whether we should sort queued email descending; otherwise, ascending.</param>+ /// <param name="referenceId">Reference object</param>+ /// <param name="objectId">Object reference id</param>/// <param name="pageIndex">Page index</param>/// <param name="pageSize">Page size</param>/// <returns>Queued emails</returns>Task<IPagedList<QueuedEmail>> SearchEmails(string fromEmail,string toEmail, string text, DateTime? createdFromUtc, DateTime? createdToUtc,bool loadNotSentItemsOnly, bool loadOnlyItemsToBeSent, int maxSendTries,- bool loadNewest, int pageIndex = 0, int pageSize = int.MaxValue);+ bool loadNewest, int referenceId = -1, string objectId = "",+ int pageIndex = 0, int pageSize = int.MaxValue);/// <summary>/// Delete all queued emailsdiff --git a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs b/src/Business/Grand.Business.Messages/Services/MessageProviderService.csindex 4018c4df0..ea3e0632a 100644--- a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs+++ b/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs@@ -176,7 +176,7 @@ namespace Grand.Business.Messages.Servicesvar toName = toEmailAccount ? emailAccount.DisplayName : customer.GetFullName();return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName, reference: Reference.Customer, objectId: customer.Id);}/// <summary>@@ -341,7 +341,8 @@ namespace Grand.Business.Messages.Servicesvar toName = emailAccount.DisplayName;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Order, objectId: order.Id);}@@ -463,7 +464,8 @@ namespace Grand.Business.Messages.ServicestoEmail, toName,attachmentFilePath,attachmentFileName,- attachments);+ attachments,+ reference: Reference.Order, objectId: order.Id);}@@ -545,7 +547,8 @@ namespace Grand.Business.Messages.Servicesvar toName = vendor.Name;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Order, objectId: order.Id);}@@ -614,7 +617,8 @@ namespace Grand.Business.Messages.Servicesvar toName = string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName);return await SendNotification(messageTemplate, emailAccount,language.Id, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Shipment, objectId: shipment.Id);}@@ -658,7 +662,8 @@ namespace Grand.Business.Messages.Servicesvar toName = string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName);return await SendNotification(messageTemplate, emailAccount,language.Id, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Order, objectId: order.Id);}#endregion@@ -724,7 +729,8 @@ namespace Grand.Business.Messages.Servicesvar toName = "";return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: subscription.CustomerId);}#endregion@@ -773,7 +779,8 @@ namespace Grand.Business.Messages.Servicesvar toName = "";return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer.Id);}/// <summary>@@ -816,7 +823,8 @@ namespace Grand.Business.Messages.Servicesvar toName = "";return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer.Id);}@@ -894,7 +902,8 @@ namespace Grand.Business.Messages.Services}return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName, replyToEmailAddress: customerEmail);+ toEmail, toName, replyToEmailAddress: customerEmail,+ reference: Reference.Customer, objectId: customer.Id);}#endregion@@ -954,7 +963,8 @@ namespace Grand.Business.Messages.Servicesvar toName = emailAccount.DisplayName;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.MerchandiseReturn, objectId: merchandiseReturn.Id);}/// <summary>@@ -1000,7 +1010,8 @@ namespace Grand.Business.Messages.Servicescustomer.GetFullName();return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.MerchandiseReturn, objectId: merchandiseReturn.Id);}/// <summary>@@ -1045,7 +1056,8 @@ namespace Grand.Business.Messages.Servicescustomer.GetFullName();return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.MerchandiseReturn, objectId: merchandiseReturn.Id);}/// <summary>@@ -1093,7 +1105,8 @@ namespace Grand.Business.Messages.Servicescustomer.GetFullName();return await SendNotification(messageTemplate, emailAccount,language.Id, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.MerchandiseReturn, objectId: merchandiseReturn.Id);}#endregion@@ -1137,7 +1150,8 @@ namespace Grand.Business.Messages.Servicesvar toName = emailAccount.DisplayName;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer.Id);}/// <summary>@@ -1171,7 +1185,8 @@ namespace Grand.Business.Messages.Servicesvar toEmail = emailAccount.Email;var toName = emailAccount.DisplayName;- return await SendNotification(messageTemplate, emailAccount, languageId, liquidObject, toEmail, toName);+ return await SendNotification(messageTemplate, emailAccount, languageId, liquidObject, toEmail, toName,+ reference: Reference.Vendor, objectId: vendor.Id);}@@ -1255,7 +1270,8 @@ namespace Grand.Business.Messages.Servicesvar toName = emailAccount.DisplayName;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Product, objectId: product.Id);}@@ -1302,7 +1318,8 @@ namespace Grand.Business.Messages.Servicesvar toName = vendor.Name;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer?.Id);}/// <summary>@@ -1337,7 +1354,8 @@ namespace Grand.Business.Messages.Servicesvar toName = emailAccount.DisplayName;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Product, objectId: product.Id);}/// <summary>@@ -1373,7 +1391,8 @@ namespace Grand.Business.Messages.Servicesvar toName = emailAccount.DisplayName;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Product, objectId: product.Id);}/// <summary>@@ -1409,7 +1428,8 @@ namespace Grand.Business.Messages.Servicesvar toName = emailAccount.DisplayName;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer.Id);}/// <summary>@@ -1447,7 +1467,8 @@ namespace Grand.Business.Messages.Servicesvar toName = emailAccount.DisplayName;return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Blog, objectId: blogPost.Id);}/// <summary>@@ -1565,7 +1586,8 @@ namespace Grand.Business.Messages.Servicesvar toName = customer.GetFullName();return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer?.Id);}/// <summary>@@ -1641,7 +1663,7 @@ namespace Grand.Business.Messages.ServicesfromName: fromName,subject: subject,replyToEmailAddress: senderEmail,- replyToName: senderName);+ replyToName: senderName, reference: Reference.Customer, objectId: customer?.Id);}/// <summary>@@ -1719,7 +1741,8 @@ namespace Grand.Business.Messages.ServicesfromName: fromName,subject: subject,replyToEmailAddress: senderEmail,- replyToName: senderName);+ replyToName: senderName,+ reference: Reference.Vendor, objectId: vendor?.Id);}#region Customer Action Event@@ -1765,7 +1788,8 @@ namespace Grand.Business.Messages.Servicesreturn await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer?.Id);}@@ -1819,7 +1843,8 @@ namespace Grand.Business.Messages.Servicesreturn await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer?.Id);}@@ -1861,7 +1886,8 @@ namespace Grand.Business.Messages.Servicesvar toName = customer.GetFullName();return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer.Id);}return 0;}@@ -1909,7 +1935,8 @@ namespace Grand.Business.Messages.Servicesvar toName = customer.GetFullName();await SendNotification(messageTemplate, emailAccount,languageId, liquidObject2,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer?.Id);}}return 0;@@ -1955,7 +1982,8 @@ namespace Grand.Business.Messages.Servicesvar toName = customer.GetFullName();await SendNotification(messageTemplate, emailAccount,languageId, liquidObject2,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer.Id);}}@@ -2056,7 +2084,8 @@ namespace Grand.Business.Messages.Servicesvar toName = customer.GetFullName();return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer?.Id);}#endregion@@ -2097,7 +2126,8 @@ namespace Grand.Business.Messages.Servicesreturn await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName);+ toEmail, toName,+ reference: Reference.Customer, objectId: customer.Id);}#endregion@@ -2108,15 +2138,16 @@ namespace Grand.Business.Messages.Servicesstring attachmentFilePath = null, string attachmentFileName = null,IEnumerable<string> attachedDownloads = null,string replyToEmailAddress = null, string replyToName = null,- string fromEmail = null, string fromName = null, string subject = null)+ string fromEmail = null, string fromName = null, string subject = null,+ Reference reference = Reference.None, string objectId = ""){- if (String.IsNullOrEmpty(toEmailAddress))+ if (string.IsNullOrEmpty(toEmailAddress))return 0;//retrieve translation message template datavar bcc = messageTemplate.GetTranslation(mt => mt.BccEmailAddresses, languageId);- if (String.IsNullOrEmpty(subject))+ if (string.IsNullOrEmpty(subject))subject = messageTemplate.GetTranslation(mt => mt.Subject, languageId);var body = messageTemplate.GetTranslation(mt => mt.Body, languageId);@@ -2153,6 +2184,8 @@ namespace Grand.Business.Messages.Servicesemail.EmailAccountId = emailAccount.Id;email.DontSendBeforeDateUtc = !messageTemplate.DelayBeforeSend.HasValue ? null: (DateTime?)(DateTime.UtcNow + TimeSpan.FromHours(messageTemplate.DelayPeriodId.ToHours(messageTemplate.DelayBeforeSend.Value)));+ email.Reference = reference;+ email.ObjectId = objectId;await _queuedEmailService.InsertQueuedEmail(email);return 1;diff --git a/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs b/src/Business/Grand.Business.Messages/Services/QueuedEmailService.csindex b2422322a..d15f4a538 100644--- a/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs+++ b/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs@@ -8,6 +8,7 @@ using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;+using Grand.Domain.Common;namespace Grand.Business.Messages.Services{@@ -133,14 +134,17 @@ namespace Grand.Business.Messages.Services/// <param name="createdToUtc">Created date to (UTC); null to load all records</param>/// <param name="loadNotSentItemsOnly">A value indicating whether to load only not sent emails</param>/// <param name="maxSendTries">Maximum send tries</param>+ /// <param name="loadOnlyItemsToBeSent">Load only items to be sent</param>/// <param name="loadNewest">A value indicating whether we should sort queued email descending; otherwise, ascending.</param>+ /// <param name="referenceId">Reference object</param>+ /// <param name="objectId">Object reference id</param>/// <param name="pageIndex">Page index</param>/// <param name="pageSize">Page size</param>/// <returns>Email item list</returns>public virtual async Task<IPagedList<QueuedEmail>> SearchEmails(string fromEmail,string toEmail, string text, DateTime? createdFromUtc, DateTime? createdToUtc,bool loadNotSentItemsOnly, bool loadOnlyItemsToBeSent, int maxSendTries,- bool loadNewest, int pageIndex = 0, int pageSize = int.MaxValue)+ bool loadNewest, int referenceId = -1, string objectId = "", int pageIndex = 0, int pageSize = int.MaxValue){fromEmail = (fromEmail ?? string.Empty).Trim();toEmail = (toEmail ?? string.Empty).Trim();@@ -167,8 +171,13 @@ namespace Grand.Business.Messages.Servicesvar nowUtc = DateTime.UtcNow;query = query.Where(qe => !qe.DontSendBeforeDateUtc.HasValue || qe.DontSendBeforeDateUtc.Value <= nowUtc);}+ if (referenceId >= 0)+ {+ query = query.Where(qe => qe.Reference == (Reference)referenceId && qe.ObjectId == objectId);+ }+ if (maxSendTries > 0)+ query = query.Where(qe => qe.SentTries < maxSendTries);- query = query.Where(qe => qe.SentTries < maxSendTries);if (loadNewest){//load the newest recordsdiff --git a/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/QueuedMessagesSendScheduleTask.cs b/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/QueuedMessagesSendScheduleTask.csindex 2b96ff455..363edf2d7 100644--- a/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/QueuedMessagesSendScheduleTask.cs+++ b/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/QueuedMessagesSendScheduleTask.cs@@ -33,7 +33,7 @@ namespace Grand.Business.System.Services.BackgroundServices.ScheduleTaskspublic async Task Execute(){var maxTries = 3;- var queuedEmails = await _queuedEmailService.SearchEmails(null, null, null, null, null, true, true, maxTries, false, 0, 500);+ var queuedEmails = await _queuedEmailService.SearchEmails(null, null, null, null, null, true, true, maxTries, false, -1, null, 0, 500);foreach (var queuedEmail in queuedEmails){var bcc = String.IsNullOrWhiteSpace(queuedEmail.Bcc)diff --git a/src/Core/Grand.Domain/Common/Reference.cs b/src/Core/Grand.Domain/Common/Reference.csindex 79a8f1ea8..76d4ec6af 100644--- a/src/Core/Grand.Domain/Common/Reference.cs+++ b/src/Core/Grand.Domain/Common/Reference.cs@@ -59,6 +59,18 @@/// </summary>Widget = 120,/// <summary>+ /// Campaign+ /// </summary>+ Campaign = 130,+ /// <summary>+ /// Customer reminder+ /// </summary>+ CustomerReminder = 140,+ /// <summary>+ /// Customer+ /// </summary>+ Customer = 150,+ /// <summary>/// Other 1/// </summary>Other1 = 901,diff --git a/src/Core/Grand.Domain/Messages/QueuedEmail.cs b/src/Core/Grand.Domain/Messages/QueuedEmail.csindex 35760ee8e..8b97b6c0e 100644--- a/src/Core/Grand.Domain/Messages/QueuedEmail.cs+++ b/src/Core/Grand.Domain/Messages/QueuedEmail.cs@@ -1,4 +1,5 @@-using System;+using Grand.Domain.Common;+using System;using System.Collections.Generic;namespace Grand.Domain.Messages@@ -112,6 +113,14 @@ namespace Grand.Domain.Messages/// </summary>public string EmailAccountId { get; set; }+ /// <summary>+ /// Gets or sets an reference identifier+ /// </summary>+ public Reference Reference { get; set; }+ /// <summary>+ /// Gets or sets an object reference identifier+ /// </summary>+ public string ObjectId { get; set; }}}diff --git a/src/Tests/Grand.Business.System.Tests/Services/BackgroundService/QueuedMessagesSendScheduleTaskTests.cs b/src/Tests/Grand.Business.System.Tests/Services/BackgroundService/QueuedMessagesSendScheduleTaskTests.csindex 3e5cd8686..1409da2b3 100644--- a/src/Tests/Grand.Business.System.Tests/Services/BackgroundService/QueuedMessagesSendScheduleTaskTests.cs+++ b/src/Tests/Grand.Business.System.Tests/Services/BackgroundService/QueuedMessagesSendScheduleTaskTests.cs@@ -36,7 +36,7 @@ namespace Grand.Business.System.Tests.Services.BackgroundServicepublic async Task Execute_InovekExpectedMethods(){_queuedEmailServiceMock.Setup(c => c.SearchEmails(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime?>(),- It.IsAny<DateTime?>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<bool>(),+ It.IsAny<DateTime?>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<string>(),It.IsAny<int>(), It.IsAny<int>())).ReturnsAsync(() => new PagedList<QueuedEmail>() { new QueuedEmail() { Bcc = "bcc", CC = "cc", EmailAccountId = "id" } });_emailAccountServiceMock.Setup(c => c.GetEmailAccountById(It.IsAny<string>())).ReturnsAsync(new EmailAccount());@@ -53,7 +53,7 @@ namespace Grand.Business.System.Tests.Services.BackgroundServicepublic async Task Execute_ThrowExecption_InovekExpectedMethodsAndInsertLog(){_queuedEmailServiceMock.Setup(c => c.SearchEmails(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime?>(),- It.IsAny<DateTime?>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<bool>(),+ It.IsAny<DateTime?>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<string>(),It.IsAny<int>(), It.IsAny<int>())).ReturnsAsync(() => new PagedList<QueuedEmail>() { new QueuedEmail() { Bcc = "bcc", CC = "cc", EmailAccountId = "id" } });_emailAccountServiceMock.Setup(c => c.GetEmailAccountById(It.IsAny<string>())).ReturnsAsync(new EmailAccount());_emailSenderMock.Setup(c => c.SendEmail(It.IsAny<EmailAccount>(), It.IsAny<string>(), It.IsAny<string>(),diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Edit.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Edit.cshtmlindex af67c147d..94ee7c629 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Edit.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Edit.cshtml@@ -6,6 +6,7 @@//has "Manage Documents" permission?var canManageDocuments = await permissionService.Authorize(Grand.Business.Common.Services.Security.StandardPermission.ManageDocuments);var canManageUserFields = await permissionService.Authorize(Grand.Business.Common.Services.Security.StandardPermission.ManageUserFields);+ var canManageMessageQueue = await permissionService.Authorize(Grand.Business.Common.Services.Security.StandardPermission.ManageMessageQueue);}<form asp-area="@Constants.AreaAdmin" asp-controller="Order" asp-action="Edit" method="post" id="order-form"><input type="hidden" asp-for="Id" />@@ -118,6 +119,16 @@</content></tabstrip-item>}+ @if (canManageMessageQueue)+ {+ <tabstrip-item text="@Loc["Admin.Orders.Notifications"]" tab-index="7">+ <content>+ <div>+ <partial name="_OrderDetails.Notifications" model="Model" />+ </div>+ </content>+ </tabstrip-item>+ }<vc:admin-widget widget-zone="order_details_tabs" additional-data="Model" /></items></admin-tabstrip>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/_OrderDetails.Notifications.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/_OrderDetails.Notifications.cshtmlnew file mode 100644index 000000000..d7d18a286--- /dev/null+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/_OrderDetails.Notifications.cshtml@@ -0,0 +1,71 @@+@model OrderModel+@inject AdminAreaSettings adminAreaSettings+<div class="panel panel-default">+ <vc:admin-widget widget-zone="order_details_notifications_top" additional-data="Model" />+ <div class="panel-body">+ <div id="order-notifications-grid"></div>+ </div>+ <vc:admin-widget widget-zone="order_details_notifications_bottom" additional-data="Model" />+</div>++<script>+$(document).ready(function () {+ $("#order-notifications-grid").kendoGrid({+ dataSource: {+ transport: {+ read: {+ url: "@Html.Raw(Url.Action("QueuedEmailByReference", "QueuedEmail", new { reference = (int)Reference.Order, ObjectId = Model.Id, area = Constants.AreaAdmin }))",+ type: "POST",+ dataType: "json",+ data: addAntiForgeryToken+ },+ },+ schema: {+ data: "Data",+ total: "Total",+ errors: "Errors",+ },+ error: function(e) {+ display_kendoui_grid_error(e);+ // Cancel the changes+ this.cancelChanges();+ },+ pageSize: @(adminAreaSettings.DefaultGridPageSize),+ serverPaging: true,+ serverFiltering: true,+ serverSorting: true+ },+ pageable: {+ refresh: true,+ pageSizes: [@(adminAreaSettings.GridPageSizes)]+ },+ editable: {+ confirmation: true,+ mode: "inline"+ },+ scrollable: false,+ columns: [{+ field: "Subject",+ title: "@Loc["Admin.System.QueuedEmails.Fields.Subject"]",+ width: 300,+ template: '<a class="k-link" href="@Url.Action("Edit", "QueuedEmail")/#=Id#">#=kendo.htmlEncode(Subject)#</a>',+ }, {+ field: "To",+ title: "@Loc["Admin.System.QueuedEmails.Fields.To"]",+ width: 100+ }, {+ field: "CreatedOn",+ title: "@Loc["Admin.System.QueuedEmails.Fields.CreatedOn"]",+ width: 100,+ type: "date",+ format: "{0:G}"+ }, {+ field: "SentOn",+ title: "@Loc["Admin.System.QueuedEmails.Fields.SentOn"]",+ width: 100,+ type: "date",+ format: "{0:G}"+ }]+ });+});+</script>\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/QueuedEmail/_CreateOrUpdate.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/QueuedEmail/_CreateOrUpdate.cshtmlindex 4cd0c4b9e..83f368ed7 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/QueuedEmail/_CreateOrUpdate.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/QueuedEmail/_CreateOrUpdate.cshtml@@ -168,6 +168,15 @@<label class="control-label">@Model.EmailAccountName</label></div></div>+ @if (!string.IsNullOrEmpty(Model.ObjectId))+ {+ <div class="form-group">+ <admin-label asp-for="Reference" />+ <div class="col-md-9 col-sm-9">+ <label class="control-label">@Model.Reference - @Model.ObjectId</label>+ </div>+ </div>+ }</div><vc:admin-widget widget-zone="queued_email_details_bottom" additional-data="Model" /></div>diff --git a/src/Web/Grand.Web.Admin/Controllers/QueuedEmailController.cs b/src/Web/Grand.Web.Admin/Controllers/QueuedEmailController.csindex e20435698..787593380 100644--- a/src/Web/Grand.Web.Admin/Controllers/QueuedEmailController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/QueuedEmailController.cs@@ -3,6 +3,7 @@ using Grand.Business.Common.Interfaces.Directory;using Grand.Business.Common.Interfaces.Localization;using Grand.Business.Common.Services.Security;using Grand.Business.Messages.Interfaces;+using Grand.Domain;using Grand.Domain.Messages;using Grand.Infrastructure;using Grand.Web.Admin.Extensions;@@ -40,6 +41,29 @@ namespace Grand.Web.Admin.Controllers_workContext = workContext;}+ private DataSourceResult PrepareDataSource(IPagedList<QueuedEmail> queuedEmails)+ {+ return new DataSourceResult {+ Data = queuedEmails.Select((Func<QueuedEmail, QueuedEmailModel>)(x =>+ {+ var m = x.ToModel();+ m.PriorityName = TranslateExtensions.GetTranslationEnum<QueuedEmailPriority>(x.PriorityId, (ITranslationService)_translationService, (IWorkContext)_workContext);+ m.CreatedOn = _dateTimeService.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);+ if (x.DontSendBeforeDateUtc.HasValue)+ m.DontSendBeforeDate = _dateTimeService.ConvertToUserTime(x.DontSendBeforeDateUtc.Value, DateTimeKind.Utc);+ if (x.SentOnUtc.HasValue)+ m.SentOn = _dateTimeService.ConvertToUserTime(x.SentOnUtc.Value, DateTimeKind.Utc);+ if (x.ReadOnUtc.HasValue)+ m.ReadOn = _dateTimeService.ConvertToUserTime(x.ReadOnUtc.Value, DateTimeKind.Utc);++ m.Body = "";++ return m;+ })),+ Total = queuedEmails.TotalCount+ };+ }+public IActionResult Index() => RedirectToAction("List");[PermissionAuthorizeAction(PermissionActionName.List)]@@ -65,29 +89,10 @@ namespace Grand.Web.Admin.Controllersvar queuedEmails = await _queuedEmailService.SearchEmails(model.SearchFromEmail, model.SearchToEmail, model.SearchText,startDateValue, endDateValue,- model.SearchLoadNotSent, false, model.SearchMaxSentTries, true,+ model.SearchLoadNotSent, false, model.SearchMaxSentTries, true,-1, null,command.Page - 1, command.PageSize);- var gridModel = new DataSourceResult- {- Data = queuedEmails.Select((Func<QueuedEmail, QueuedEmailModel>)(x =>- {- var m = x.ToModel();- m.PriorityName = TranslateExtensions.GetTranslationEnum<QueuedEmailPriority>(x.PriorityId, (ITranslationService)_translationService, (IWorkContext)_workContext);- m.CreatedOn = _dateTimeService.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);- if (x.DontSendBeforeDateUtc.HasValue)- m.DontSendBeforeDate = _dateTimeService.ConvertToUserTime(x.DontSendBeforeDateUtc.Value, DateTimeKind.Utc);- if (x.SentOnUtc.HasValue)- m.SentOn = _dateTimeService.ConvertToUserTime(x.SentOnUtc.Value, DateTimeKind.Utc);- if (x.ReadOnUtc.HasValue)- m.ReadOn = _dateTimeService.ConvertToUserTime(x.ReadOnUtc.Value, DateTimeKind.Utc);-- m.Body = "";-- return m;- })),- Total = queuedEmails.TotalCount- };- return Json(gridModel);++ return Json(PrepareDataSource(queuedEmails));}[PermissionAuthorizeAction(PermissionActionName.Preview)][HttpPost]@@ -99,6 +104,19 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("Edit", "QueuedEmail", new { id = queuedEmail.Id });}++ [PermissionAuthorizeAction(PermissionActionName.List)]+ [HttpPost]+ public async Task<IActionResult> QueuedEmailByReference(DataSourceRequest command, int reference, string objectId)+ {+ var queuedEmails = await _queuedEmailService.SearchEmails(null, null, null,+ null, null,+ false, false, 10, true, reference, objectId,+ command.Page - 1, command.PageSize);++ return Json(PrepareDataSource(queuedEmails));+ }+[PermissionAuthorizeAction(PermissionActionName.Preview)]public async Task<IActionResult> Edit(string id){diff --git a/src/Web/Grand.Web.Admin/Models/Messages/QueuedEmailModel.cs b/src/Web/Grand.Web.Admin/Models/Messages/QueuedEmailModel.csindex d03c09fa8..f45984b22 100644--- a/src/Web/Grand.Web.Admin/Models/Messages/QueuedEmailModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Messages/QueuedEmailModel.cs@@ -1,4 +1,5 @@-using Grand.Infrastructure.ModelBinding;+using Grand.Domain.Common;+using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;using System;using System.ComponentModel.DataAnnotations;@@ -80,7 +81,11 @@ namespace Grand.Web.Admin.Models.Messagespublic DateTime? ReadOn { get; set; }[GrandResourceDisplayName("Admin.System.QueuedEmails.Fields.EmailAccountName")]-public string EmailAccountName { get; set; }++ [GrandResourceDisplayName("Admin.System.QueuedEmails.Fields.Reference")]+ public Reference Reference { get; set; }++ public string ObjectId { get; set; }}}\ No newline at end of filediff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xmlindex 7122dc6d7..b6e65fd4c 100644--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml@@ -9304,6 +9304,9 @@<Resource Name="Admin.Orders.MerchandiseReturns.View"><Value>View</Value></Resource>+ <Resource Name="Admin.Orders.Notifications">+ <Value>Notifications</Value>+ </Resource><Resource Name="Admin.Orders.OrderNotes"><Value>Order notes</Value></Resource>@@ -12264,8 +12267,11 @@<Resource Name="Admin.System.QueuedEmails.Fields.ReadOn.notread"><Value>Not read</Value></Resource>- <Resource Name="Admin.System.QueuedEmails.Fields.ReplyTo">- <Value>ReplyTo</Value>+ <Resource Name="Admin.System.QueuedEmails.Fields.ReadOn.notread">+ <Value>Not read</Value>+ </Resource>+ <Resource Name="Admin.System.QueuedEmails.Fields.Reference">+ <Value>Reference to the object</Value></Resource><Resource Name="Admin.System.QueuedEmails.Fields.ReplyToName"><Value>ReplyTo name</Value>