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
Minor changes
support99efd18c7335
diff --git a/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs b/src/Business/Grand.Business.Messages/Services/EmailAccountService.csindex 0bcdea214..13b369ecc 100644--- a/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs+++ b/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs@@ -132,11 +132,8 @@ namespace Grand.Business.Messages.Services/// <returns>Email account</returns>public virtual async Task<EmailAccount> GetEmailAccountById(string emailAccountId){- string key = string.Format(CacheKey.EMAILACCOUNT_BY_ID_KEY, emailAccountId);- return await _cacheBase.GetAsync(key, () =>- {- return _emailAccountRepository.GetByIdAsync(emailAccountId);- });+ var key = string.Format(CacheKey.EMAILACCOUNT_BY_ID_KEY, emailAccountId);+ return await _cacheBase.GetAsync(key, () => _emailAccountRepository.GetByIdAsync(emailAccountId));}diff --git a/src/Business/Grand.Business.Messages/Services/EmailSender.cs b/src/Business/Grand.Business.Messages/Services/EmailSender.csindex 5fabc33b0..68e42c8a1 100644--- a/src/Business/Grand.Business.Messages/Services/EmailSender.cs+++ b/src/Business/Grand.Business.Messages/Services/EmailSender.cs@@ -40,7 +40,7 @@ namespace Grand.Business.Messages.Services/// <param name="attachedDownloads">Attachment download ID (another attachedment)</param>public virtual async Task SendEmail(EmailAccount emailAccount, string subject, string body,string fromAddress, string fromName, string toAddress, string toName,- string replyToAddress = null, string replyToName = null,+ string replyToAddress = null, string replyToName = null,IEnumerable<string> bccAddresses = null, IEnumerable<string> ccAddresses = null,string attachmentFilePath = null, string attachmentFileName = null,IEnumerable<string> attachedDownloads = null)@@ -84,13 +84,10 @@ namespace Grand.Business.Messages.Servicesif (!String.IsNullOrEmpty(attachmentFilePath) &&File.Exists(attachmentFilePath)){-// TODO: should probably include a check for the attachmentFileName not being null or white space- var attachment = new MimePart(_mimeMappingService.Map(attachmentFileName))- {- Content = new MimeContent(File.OpenRead(attachmentFilePath), ContentEncoding.Default),- ContentDisposition = new ContentDisposition(ContentDisposition.Attachment)- {+ var attachment = new MimePart(_mimeMappingService.Map(attachmentFileName)) {+ Content = new MimeContent(File.OpenRead(attachmentFilePath)),+ ContentDisposition = new ContentDisposition(ContentDisposition.Attachment) {CreationDate = File.GetCreationTime(attachmentFilePath),ModificationDate = File.GetLastWriteTime(attachmentFilePath),ReadDate = File.GetLastAccessTime(attachmentFilePath)@@ -99,51 +96,45 @@ namespace Grand.Business.Messages.ServicesFileName = Path.GetFileName(attachmentFilePath),};builder.Attachments.Add(attachment);-}+//another attachment?if (attachedDownloads != null){foreach (var attachedDownloadId in attachedDownloads){var download = await _downloadService.GetDownloadById(attachedDownloadId);- if (download != null)- {- //we do not support URLs as attachments- if (!download.UseDownloadUrl)- {- string fileName = !String.IsNullOrWhiteSpace(download.Filename) ? download.Filename : download.Id;- fileName += download.Extension;- var ms = new MemoryStream(download.DownloadBinary);- var attachment = new MimePart(download.ContentType ?? _mimeMappingService.Map(fileName))- {- Content = new MimeContent(ms, ContentEncoding.Default),- ContentDisposition = new ContentDisposition(ContentDisposition.Attachment)- {- CreationDate = DateTime.UtcNow,- ModificationDate = DateTime.UtcNow,- ReadDate = DateTime.UtcNow- },- ContentTransferEncoding = ContentEncoding.Base64,- FileName = fileName,- };- builder.Attachments.Add(attachment);- }- }+ if (download == null || download.UseDownloadUrl) continue;+ var fileName = !string.IsNullOrWhiteSpace(download.Filename) ? download.Filename : download.Id;+ fileName += download.Extension;+ var ms = new MemoryStream(download.DownloadBinary);+ var attachment = new MimePart(download.ContentType ?? _mimeMappingService.Map(fileName)) {+ Content = new MimeContent(ms),+ ContentDisposition = new ContentDisposition(ContentDisposition.Attachment) {+ CreationDate = DateTime.UtcNow,+ ModificationDate = DateTime.UtcNow,+ ReadDate = DateTime.UtcNow+ },+ ContentTransferEncoding = ContentEncoding.Base64,+ FileName = fileName,+ };+ builder.Attachments.Add(attachment);}}+message.Body = builder.ToMessageBody();//send emailusing (var smtpClient = new SmtpClient()){- smtpClient.ServerCertificateValidationCallback = (s, c, h, e) => emailAccount.UseServerCertificateValidation;- await smtpClient.ConnectAsync(emailAccount.Host, emailAccount.Port, (SecureSocketOptions)emailAccount.SecureSocketOptionsId);+ smtpClient.ServerCertificateValidationCallback =+ (s, c, h, e) => emailAccount.UseServerCertificateValidation;+ await smtpClient.ConnectAsync(emailAccount.Host, emailAccount.Port,+ (SecureSocketOptions)emailAccount.SecureSocketOptionsId);await smtpClient.AuthenticateAsync(emailAccount.Username, emailAccount.Password);await smtpClient.SendAsync(message);await smtpClient.DisconnectAsync(true);}-}}}\ No newline at end of filediff --git a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs b/src/Business/Grand.Business.Messages/Services/MessageProviderService.csindex 189438552..acf7df339 100644--- a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs+++ b/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs@@ -141,7 +141,6 @@ namespace Grand.Business.Messages.Services/// <param name="templateName">Message template name</param>/// <param name="toEmailAccount">Send email to email account</param>/// <param name="customerNote">Customer note</param>- /// <returns>Queued email identifier</returns>protected virtual async Task<int> SendCustomerMessage(Customer customer, Store store, string languageId, string templateName, bool toEmailAccount = false, CustomerNote customerNote = null){if (customer == null)@@ -189,7 +188,6 @@ namespace Grand.Business.Messages.Services/// <param name="customer">Customer instance</param>/// <param name="store">Store</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendCustomerWelcomeMessage(Customer customer, Store store, string languageId){return await SendCustomerMessage(customer, store, languageId, MessageTemplateNames.CustomerWelcome);@@ -201,7 +199,6 @@ namespace Grand.Business.Messages.Services/// <param name="customer">Customer instance</param>/// <param name="store">Store</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendCustomerEmailValidationMessage(Customer customer, Store store, string languageId){return await SendCustomerMessage(customer, store, languageId, MessageTemplateNames.CustomerEmailValidation);@@ -213,7 +210,6 @@ namespace Grand.Business.Messages.Services/// <param name="customer">Customer instance</param>/// <param name="store">Store</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendCustomerPasswordRecoveryMessage(Customer customer, Store store, string languageId){return await SendCustomerMessage(customer, store, languageId, MessageTemplateNames.CustomerPasswordRecovery);@@ -237,9 +233,7 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="customer">Customer instance</param>/// <param name="store">Store instance</param>- /// <param name="token">Token</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendCustomerEmailTokenValidationMessage(Customer customer, Store store, string languageId){return await SendCustomerMessage(customer, store, languageId, MessageTemplateNames.CustomerEmailTokenValidationMessage);@@ -255,7 +249,6 @@ namespace Grand.Business.Messages.Services/// <param name="order">Order instance</param>/// <param name="customer">Customer</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderPlacedStoreOwnerMessage(Order order, Customer customer, string languageId){return await SendOrderStoreOwnerMessage(MessageTemplateNames.SendOrderPlacedStoreOwnerMessage, order, customer, languageId);@@ -267,7 +260,6 @@ namespace Grand.Business.Messages.Services/// <param name="order">Order instance</param>/// <param name="customer">Customer instance</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderPaidStoreOwnerMessage(Order order, Customer customer, string languageId){return await SendOrderStoreOwnerMessage(MessageTemplateNames.SendOrderPaidStoreOwnerMessage, order, customer, languageId);@@ -286,11 +278,9 @@ namespace Grand.Business.Messages.Services}/// Sends an order refunded notification to a store owner- /// </summary>/// <param name="order">Order instance</param>/// <param name="refundedAmount">Amount refunded</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderRefundedStoreOwnerMessage(Order order, double refundedAmount, string languageId){var customer = await _mediator.Send(new GetCustomerByIdQuery() { Id = order.CustomerId });@@ -303,7 +293,6 @@ namespace Grand.Business.Messages.Services/// <param name="order">Order instance</param>/// <param name="customer">Customer instance</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>private async Task<int> SendOrderStoreOwnerMessage(string template, Order order, Customer customer, string languageId, double refundedAmount = 0){if (order == null)@@ -336,8 +325,6 @@ namespace Grand.Business.Messages.ServicestoEmail, toName,reference: Reference.Order, objectId: order.Id);}--/// <summary>/// Sends an order placed notification to a customer/// </summary>@@ -347,7 +334,6 @@ namespace Grand.Business.Messages.Services/// <param name="attachmentFilePath">Attachment file path</param>/// <param name="attachmentFileName">Attachment file name. If specified, then this file name will be sent to a recipient. Otherwise, "AttachmentFilePath" name will be used.</param>/// <param name="attachments">Attachments</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderPlacedCustomerMessage(Order order, Customer customer, string languageId,string attachmentFilePath = null, string attachmentFileName = null, IEnumerable<string> attachments = null){@@ -363,7 +349,6 @@ namespace Grand.Business.Messages.Services/// <param name="attachmentFilePath">Attachment file path</param>/// <param name="attachmentFileName">Attachment file name. If specified, then this file name will be sent to a recipient. Otherwise, "AttachmentFilePath" name will be used.</param>/// <param name="attachments">Attachments ident</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderPaidCustomerMessage(Order order, Customer customer, string languageId,string attachmentFilePath = null, string attachmentFileName = null, IEnumerable<string> attachments = null){@@ -379,7 +364,6 @@ namespace Grand.Business.Messages.Services/// <param name="attachmentFilePath">Attachment file path</param>/// <param name="attachmentFileName">Attachment file name. If specified, then this file name will be sent to a recipient. Otherwise, "AttachmentFilePath" name will be used.</param>/// <param name="attachments">Attachments ident</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderCompletedCustomerMessage(Order order, Customer customer, string languageId,string attachmentFilePath = null, string attachmentFileName = null, IEnumerable<string> attachments = null){@@ -392,7 +376,6 @@ namespace Grand.Business.Messages.Services/// <param name="order">Order instance</param>/// <param name="customer">Customer instance</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderCancelledCustomerMessage(Order order, Customer customer, string languageId){return await SendOrderCustomerMessage(MessageTemplateNames.SendOrderCancelledCustomerMessage, order, customer, languageId);@@ -421,7 +404,6 @@ namespace Grand.Business.Messages.Services/// <param name="attachmentFilePath">Attachment file path</param>/// <param name="attachmentFileName">Attachment file name. If specified, then this file name will be sent to a recipient. Otherwise, "AttachmentFilePath" name will be used.</param>/// <param name="attachments">Attachments ident</param>- /// <returns>Queued email identifier</returns>private async Task<int> SendOrderCustomerMessage(string message, Order order, Customer customer, string languageId,string attachmentFilePath = null, string attachmentFileName = null, IEnumerable<string> attachments = null, double refundedAmount = 0){@@ -450,7 +432,7 @@ namespace Grand.Business.Messages.Servicesawait _mediator.MessageTokensAdded(messageTemplate, liquidObject);var toEmail = order.BillingAddress.Email;- var toName = string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName);+ var toName = $"{order.BillingAddress.FirstName} {order.BillingAddress.LastName}";return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,toEmail, toName,@@ -460,7 +442,6 @@ namespace Grand.Business.Messages.Servicesreference: Reference.Order, objectId: order.Id);}-/// <summary>/// Sends an order placed notification to a vendor/// </summary>@@ -468,7 +449,6 @@ namespace Grand.Business.Messages.Services/// <param name="customer">Customer instance</param>/// <param name="vendor">Vendor instance</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderPlacedVendorMessage(Order order, Customer customer, Vendor vendor, string languageId){return await SendOrderVendorMessage(MessageTemplateNames.SendOrderPlacedVendorMessage, order, vendor, languageId);@@ -480,7 +460,6 @@ namespace Grand.Business.Messages.Services/// <param name="order">Order instance</param>/// <param name="vendor">Vendor instance</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderPaidVendorMessage(Order order, Vendor vendor, string languageId){return await SendOrderVendorMessage(MessageTemplateNames.SendOrderPaidVendorMessage, order, vendor, languageId);@@ -491,7 +470,6 @@ namespace Grand.Business.Messages.Services/// <param name="order">Order instance</param>/// <param name="vendor">Vendor instance</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOrderCancelledVendorMessage(Order order, Vendor vendor, string languageId){return await SendOrderVendorMessage(MessageTemplateNames.SendOrderCancelledVendorMessage, order, vendor, languageId);@@ -503,7 +481,6 @@ namespace Grand.Business.Messages.Services/// <param name="order">Order instance</param>/// <param name="vendor">Vendor instance</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>private async Task<int> SendOrderVendorMessage(string message, Order order, Vendor vendor, string languageId){if (order == null)@@ -549,7 +526,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="shipment">Shipment</param>/// <param name="order">Order</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendShipmentSentCustomerMessage(Shipment shipment, Order order){return await SendShipmentCustomerMessage(MessageTemplateNames.SendShipmentSentCustomerMessage, shipment, order);@@ -560,7 +536,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="shipment">Shipment</param>/// <param name="order">Order</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendShipmentDeliveredCustomerMessage(Shipment shipment, Order order){return await SendShipmentCustomerMessage(MessageTemplateNames.SendShipmentDeliveredCustomerMessage, shipment, order);@@ -572,7 +547,6 @@ namespace Grand.Business.Messages.Services/// <param name="message">Message template</param>/// <param name="shipment">Shipment</param>/// <param name="order">Order</param>- /// <returns>Queued email identifier</returns>private async Task<int> SendShipmentCustomerMessage(string message, Shipment shipment, Order order){if (shipment == null)@@ -606,7 +580,7 @@ namespace Grand.Business.Messages.Servicesawait _mediator.MessageTokensAdded(messageTemplate, liquidObject);var toEmail = order.BillingAddress.Email;- var toName = string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName);+ var toName = $"{order.BillingAddress.FirstName} {order.BillingAddress.LastName}";return await SendNotification(messageTemplate, emailAccount,language.Id, liquidObject,toEmail, toName,@@ -619,7 +593,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="order">Order</param>/// <param name="orderNote">Order note</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendNewOrderNoteAddedCustomerMessage(Order order, OrderNote orderNote){if (orderNote == null)@@ -651,7 +624,7 @@ namespace Grand.Business.Messages.Servicesawait _mediator.MessageTokensAdded(messageTemplate, liquidObject);var toEmail = order.BillingAddress.Email;- var toName = string.Format("{0} {1}", order.BillingAddress.FirstName, order.BillingAddress.LastName);+ var toName = $"{order.BillingAddress.FirstName} {order.BillingAddress.LastName}";return await SendNotification(messageTemplate, emailAccount,language.Id, liquidObject,toEmail, toName,@@ -667,7 +640,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="subscription">Newsletter subscription</param>/// <param name="languageId">Language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendNewsLetterSubscriptionActivationMessage(NewsLetterSubscription subscription,string languageId){@@ -679,7 +651,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="subscription">Newsletter subscription</param>/// <param name="languageId">Language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendNewsLetterSubscriptionDeactivationMessage(NewsLetterSubscription subscription,string languageId){@@ -692,7 +663,6 @@ namespace Grand.Business.Messages.Services/// <param name="message">Message template</param>/// <param name="subscription">Newsletter subscription</param>/// <param name="languageId">Language identifier</param>- /// <returns>Queued email identifier</returns>private async Task<int> SendNewsLetterSubscriptionMessage(string message, NewsLetterSubscription subscription,string languageId){@@ -718,10 +688,9 @@ namespace Grand.Business.Messages.Servicesawait _mediator.MessageTokensAdded(messageTemplate, liquidObject);var toEmail = subscription.Email;- var toName = "";return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,- toEmail, toName,+ toEmail, string.Empty,reference: Reference.Customer, objectId: subscription.CustomerId);}#endregion@@ -900,9 +869,8 @@ namespace Grand.Business.Messages.Services/// Sends 'New Merchandise Return' message to a store owner/// </summary>/// <param name="merchandiseReturn">Merchandise return</param>- /// <param name="orderItem">Order</param>+ /// <param name="order">Order</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendNewMerchandiseReturnStoreOwnerMessage(MerchandiseReturn merchandiseReturn, Order order, string languageId){if (merchandiseReturn == null)@@ -959,7 +927,6 @@ namespace Grand.Business.Messages.Services/// <param name="merchandiseReturn">Merchandise return</param>/// <param name="order">Order</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendMerchandiseReturnStatusChangedCustomerMessage(MerchandiseReturn merchandiseReturn, Order order, string languageId){if (merchandiseReturn == null)@@ -976,8 +943,7 @@ namespace Grand.Business.Messages.Servicesvar emailAccount = await GetEmailAccountOfMessageTemplate(messageTemplate, language.Id);var customer = await _mediator.Send(new GetCustomerByIdQuery() { Id = merchandiseReturn.CustomerId });--+var builder = new LiquidObjectBuilder(_mediator);builder.AddStoreTokens(store, language, emailAccount);if (customer != null)@@ -988,10 +954,10 @@ namespace Grand.Business.Messages.Services//event notificationawait _mediator.MessageTokensAdded(messageTemplate, liquidObject);- string toEmail = string.IsNullOrEmpty(customer.Email) ?+ var toEmail = string.IsNullOrEmpty(customer?.Email) ?order.BillingAddress.Email :customer.Email;- var toName = string.IsNullOrEmpty(customer.Email) ?+ var toName = string.IsNullOrEmpty(customer?.Email) ?order.BillingAddress.FirstName :customer.GetFullName();return await SendNotification(messageTemplate, emailAccount,@@ -1006,7 +972,6 @@ namespace Grand.Business.Messages.Services/// <param name="merchandiseReturn">Merchandise return</param>/// <param name="order">Order</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendNewMerchandiseReturnCustomerMessage(MerchandiseReturn merchandiseReturn, Order order, string languageId){if (merchandiseReturn == null)@@ -1034,10 +999,10 @@ namespace Grand.Business.Messages.Services//event notificationawait _mediator.MessageTokensAdded(messageTemplate, liquidObject);- var toEmail = string.IsNullOrEmpty(customer.Email) ?+ var toEmail = string.IsNullOrEmpty(customer?.Email) ?order.BillingAddress.Email :customer.Email;- var toName = string.IsNullOrEmpty(customer.Email) ?+ var toName = string.IsNullOrEmpty(customer?.Email) ?order.BillingAddress.FirstName :customer.GetFullName();return await SendNotification(messageTemplate, emailAccount,@@ -1052,7 +1017,6 @@ namespace Grand.Business.Messages.Services/// <param name="merchandiseReturn">Merchandise return</param>/// <param name="merchandiseReturnNote">Merchandise return note</param>/// <param name="order">Order</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendNewMerchandiseReturnNoteAddedCustomerMessage(MerchandiseReturn merchandiseReturn, MerchandiseReturnNote merchandiseReturnNote, Order order){if (merchandiseReturnNote == null)@@ -1083,10 +1047,10 @@ namespace Grand.Business.Messages.Services//event notificationawait _mediator.MessageTokensAdded(messageTemplate, liquidObject);- var toEmail = string.IsNullOrEmpty(customer.Email) ?+ var toEmail = string.IsNullOrEmpty(customer?.Email) ?order.BillingAddress.Email :customer.Email;- var toName = string.IsNullOrEmpty(customer.Email) ?+ var toName = string.IsNullOrEmpty(customer?.Email) ?order.BillingAddress.FirstName :customer.GetFullName();return await SendNotification(messageTemplate, emailAccount,@@ -1106,7 +1070,6 @@ namespace Grand.Business.Messages.Services/// <param name="vendor">Vendor</param>/// <param name="store">Store</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendNewVendorAccountApplyStoreOwnerMessage(Customer customer, Vendor vendor, Store store, string languageId){if (customer == null)@@ -1146,7 +1109,6 @@ namespace Grand.Business.Messages.Services/// <param name="vendor">Vendor</param>/// <param name="store">Store</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendVendorInformationChangeMessage(Vendor vendor, Store store, string languageId){if (vendor == null)@@ -1182,17 +1144,14 @@ namespace Grand.Business.Messages.Services/// <param name="giftVoucher">Gift voucher</param>/// <param name="order">Order</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendGiftVoucherMessage(GiftVoucher giftVoucher, Order order, string languageId){if (giftVoucher == null)throw new ArgumentNullException(nameof(giftVoucher));Store store = null;- if (order != null)- store = await _storeService.GetStoreById(order.StoreId);- if (store == null)- store = (await _storeService.GetAllStores()).FirstOrDefault();+ if (order != null) store = await _storeService.GetStoreById(order.StoreId);+ store ??= (await _storeService.GetAllStores()).FirstOrDefault();var language = await EnsureLanguageIsActive(languageId, store.Id);@@ -1223,7 +1182,6 @@ namespace Grand.Business.Messages.Services/// <param name="productReview">Product review</param>/// <param name="store">Store</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendProductReviewMessage(Product product, ProductReview productReview,Store store, string languageId){@@ -1267,7 +1225,6 @@ namespace Grand.Business.Messages.Services/// <param name="vendorReview">Vendor review</param>/// <param name="store">Store</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendVendorReviewMessage(VendorReview vendorReview, Store store,string languageId){@@ -1313,7 +1270,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="product">Product</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendQuantityBelowStoreOwnerMessage(Product product, string languageId){if (product == null)@@ -1349,7 +1305,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="combination">Attribute combination</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendQuantityBelowStoreOwnerMessage(Product product, ProductAttributeCombination combination, string languageId){if (combination == null)@@ -1385,10 +1340,7 @@ namespace Grand.Business.Messages.Services/// Sends a "new VAT sumitted" notification to a store owner/// </summary>/// <param name="customer">Customer</param>- /// <param name="vatName">Received VAT name</param>- /// <param name="vatAddress">Received VAT address</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendCustomerDeleteStoreOwnerMessage(Customer customer, string languageId){if (customer == null)@@ -1421,7 +1373,6 @@ namespace Grand.Business.Messages.Services/// <summary>/// Sends a blog comment notification message to a store owner/// </summary>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendBlogCommentMessage(BlogPost blogPost, BlogComment blogComment, string languageId){if (blogComment == null)@@ -1462,7 +1413,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="articleComment">Article comment</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendArticleCommentMessage(KnowledgebaseArticle article, KnowledgebaseArticleComment articleComment, string languageId){if (articleComment == null)@@ -1499,9 +1449,9 @@ namespace Grand.Business.Messages.Services/// <summary>/// Sends a news comment notification message to a store owner/// </summary>+ /// <param name="newsItem">News item</param>/// <param name="newsComment">News comment</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendNewsCommentMessage(NewsItem newsItem, NewsComment newsComment, string languageId){if (newsComment == null)@@ -1542,7 +1492,6 @@ namespace Grand.Business.Messages.Services/// <param name="product">Product</param>/// <param name="subscription">Subscription</param>/// <param name="languageId">Message language identifier</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendBackinStockMessage(Customer customer, Product product, OutOfStockSubscription subscription, string languageId){if (subscription == null)@@ -1568,7 +1517,7 @@ namespace Grand.Business.Messages.Services//event notificationawait _mediator.MessageTokensAdded(messageTemplate, liquidObject);- var toEmail = customer.Email;+ var toEmail = customer?.Email;var toName = customer.GetFullName();return await SendNotification(messageTemplate, emailAccount,languageId, liquidObject,@@ -1588,7 +1537,7 @@ namespace Grand.Business.Messages.Services/// <param name="body">Email body</param>/// <param name="attrInfo">Attr info</param>/// <param name="customAttributes">CustomAttributes</param>- /// <returns>Queued email identifier</returns>+ /// <param name="ipaddress">Ip address</param>public virtual async Task<int> SendContactUsMessage(Customer customer, Store store, string languageId, string senderEmail,string senderName, string subject, string body, string attrInfo, IList<CustomAttribute> customAttributes, string ipaddress){@@ -1665,7 +1614,6 @@ namespace Grand.Business.Messages.Services/// <param name="subject">Email subject. Pass null if you want a message template subject to be used.</param>/// <param name="body">Email body</param>/// <param name="ipaddress">Ip address</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendContactVendorMessage(Customer customer, Store store, Vendor vendor, string languageId, string senderEmail,string senderName, string subject, string body, string ipaddress){@@ -1721,7 +1669,7 @@ namespace Grand.Business.Messages.ServicesEnquiry = body,RemoteIpAddress = ipaddress,FullName = senderName,- Subject = String.IsNullOrEmpty(subject) ? "Contact Us (form)" : subject,+ Subject = string.IsNullOrEmpty(subject) ? "Contact Us (form)" : subject,EmailAccountId = emailAccount.Id});}@@ -1784,47 +1732,46 @@ namespace Grand.Business.Messages.Servicesif (product == null)throw new ArgumentNullException(nameof(product));- var customerwin = await _mediator.Send(new GetCustomerByIdQuery() { Id = bid.CustomerId });- if (customerwin != null)- {- var store = await GetStore(bid.StoreId);+ var winner = await _mediator.Send(new GetCustomerByIdQuery() { Id = bid.CustomerId });+ if (winner == null) return 0;++ var store = await GetStore(bid.StoreId);- var language = await EnsureLanguageIsActive(languageId, store.Id);+ var language = await EnsureLanguageIsActive(languageId, store.Id);- var messageTemplate = await GetMessageTemplate("AuctionEnded.CustomerNotificationLost", store.Id);- if (messageTemplate == null)- return 0;+ var messageTemplate = await GetMessageTemplate("AuctionEnded.CustomerNotificationLost", store.Id);+ if (messageTemplate == null)+ return 0;- var emailAccount = await GetEmailAccountOfMessageTemplate(messageTemplate, language.Id);+ var emailAccount = await GetEmailAccountOfMessageTemplate(messageTemplate, language.Id);- var builder = new LiquidObjectBuilder(_mediator);- builder.AddAuctionTokens(product, bid)- .AddProductTokens(product, language, store, _storeHelper.DomainHost)- .AddStoreTokens(store, language, emailAccount);- LiquidObject liquidObject = await builder.BuildAsync();+ var builder = new LiquidObjectBuilder(_mediator);+ builder.AddAuctionTokens(product, bid)+ .AddProductTokens(product, language, store, _storeHelper.DomainHost)+ .AddStoreTokens(store, language, emailAccount);+ LiquidObject liquidObject = await builder.BuildAsync();- var bids = (await _mediator.Send(new GetBidsByProductIdQuery() { ProductId = bid.ProductId })).Where(x => x.CustomerId != bid.CustomerId).GroupBy(x => x.CustomerId);- foreach (var item in bids)+ var bids = (await _mediator.Send(new GetBidsByProductIdQuery() { ProductId = bid.ProductId })).Where(x => x.CustomerId != bid.CustomerId).GroupBy(x => x.CustomerId);+ foreach (var item in bids)+ {+ var builder2 = new LiquidObjectBuilder(_mediator, liquidObject);+ var customer = await _mediator.Send(new GetCustomerByIdQuery() { Id = item.Key });+ if (string.IsNullOrEmpty(languageId)){- var builder2 = new LiquidObjectBuilder(_mediator, liquidObject);- var customer = await _mediator.Send(new GetCustomerByIdQuery() { Id = item.Key });- if (string.IsNullOrEmpty(languageId))- {- languageId = customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LanguageId);- }- builder2.AddCustomerTokens(customer, store, _storeHelper.DomainHost, language);- LiquidObject liquidObject2 = await builder2.BuildAsync();+ languageId = customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LanguageId);+ }+ builder2.AddCustomerTokens(customer, store, _storeHelper.DomainHost, language);+ LiquidObject liquidObject2 = await builder2.BuildAsync();- //event notification- await _mediator.MessageTokensAdded(messageTemplate, liquidObject2);+ //event notification+ await _mediator.MessageTokensAdded(messageTemplate, liquidObject2);- var toEmail = customer.Email;- var toName = customer.GetFullName();- await SendNotification(messageTemplate, emailAccount,- languageId, liquidObject2,- toEmail, toName,- reference: Reference.Customer, objectId: customer?.Id);- }+ var toEmail = customer.Email;+ var toName = customer.GetFullName();+ await SendNotification(messageTemplate, emailAccount,+ languageId, liquidObject2,+ toEmail, toName,+ reference: Reference.Customer, objectId: customer?.Id);}return 0;}@@ -1935,8 +1882,6 @@ namespace Grand.Business.Messages.Services/// </summary>/// <param name="languageId">Message language identifier</param>/// <param name="product">Product</param>- /// <param name="Bid">Bid</param>- /// <returns>Queued email identifier</returns>public virtual async Task<int> SendOutBidCustomerMessage(Product product, string languageId, Bid bid){if (product == null)diff --git a/src/Business/Grand.Business.Messages/Services/MessageTemplateNames.cs b/src/Business/Grand.Business.Messages/Services/MessageTemplateNames.csindex 8232277c6..4158652d0 100644--- a/src/Business/Grand.Business.Messages/Services/MessageTemplateNames.cs+++ b/src/Business/Grand.Business.Messages/Services/MessageTemplateNames.cs@@ -1,7 +1,7 @@namespace Grand.Business.Messages{- public class MessageTemplateNames+ public static class MessageTemplateNames{public const string CustomerRegistered = "NewCustomer.Notification";public const string CustomerWelcome = "Customer.WelcomeMessage";diff --git a/src/Business/Grand.Business.Messages/Services/MessageTemplateService.cs b/src/Business/Grand.Business.Messages/Services/MessageTemplateService.csindex 0942b09f9..b47bdd8ce 100644--- a/src/Business/Grand.Business.Messages/Services/MessageTemplateService.cs+++ b/src/Business/Grand.Business.Messages/Services/MessageTemplateService.cs@@ -111,13 +111,13 @@ namespace Grand.Business.Messages.Servicespublic virtual async Task<MessageTemplate> GetMessageTemplateByName(string messageTemplateName, string storeId){if (string.IsNullOrWhiteSpace(messageTemplateName))- throw new ArgumentException("messageTemplateName");+ throw new ArgumentException(null, nameof(messageTemplateName));- string key = string.Format(CacheKey.MESSAGETEMPLATES_BY_NAME_KEY, messageTemplateName, storeId);+ var key = string.Format(CacheKey.MESSAGETEMPLATES_BY_NAME_KEY, messageTemplateName, storeId);return await _cacheBase.GetAsync(key, async () =>{var query = from p in _messageTemplateRepository.Table- select p;+ select p;query = query.Where(t => t.Name == messageTemplateName);query = query.OrderBy(t => t.Id);@@ -133,7 +133,6 @@ namespace Grand.Business.Messages.Servicesreturn templates.FirstOrDefault();});-}/// <summary>@@ -143,22 +142,23 @@ namespace Grand.Business.Messages.Services/// <returns>Message template list</returns>public virtual async Task<IList<MessageTemplate>> GetAllMessageTemplates(string storeId){- string key = string.Format(CacheKey.MESSAGETEMPLATES_ALL_KEY, storeId);+ var key = string.Format(CacheKey.MESSAGETEMPLATES_ALL_KEY, storeId);return await _cacheBase.GetAsync(key, async () =>{var query = from p in _messageTemplateRepository.Table- select p;+ select p;query = query.OrderBy(t => t.Name);//Store acl- if (!String.IsNullOrEmpty(storeId) && !CommonHelper.IgnoreStoreLimitations)- {- query = from p in query- where !p.LimitedToStores || p.Stores.Contains(storeId)- select p;- query = query.OrderBy(t => t.Name);- }+ if (string.IsNullOrEmpty(storeId) || CommonHelper.IgnoreStoreLimitations)+ return await Task.FromResult(query.ToList());++ query = from p in query+ where !p.LimitedToStores || p.Stores.Contains(storeId)+ select p;+ query = query.OrderBy(t => t.Name);+return await Task.FromResult(query.ToList());});}@@ -173,8 +173,7 @@ namespace Grand.Business.Messages.Servicesif (messageTemplate == null)throw new ArgumentNullException(nameof(messageTemplate));- var mtCopy = new MessageTemplate- {+ var mtCopy = new MessageTemplate {Name = messageTemplate.Name,BccEmailAddresses = messageTemplate.BccEmailAddresses,Subject = messageTemplate.Subject,@@ -196,4 +195,4 @@ namespace Grand.Business.Messages.Services#endregion}-}+}\ No newline at end of filediff --git a/src/Business/Grand.Business.Messages/Services/MimeMappingService.cs b/src/Business/Grand.Business.Messages/Services/MimeMappingService.csindex aa0690c67..0a54acbe0 100644--- a/src/Business/Grand.Business.Messages/Services/MimeMappingService.cs+++ b/src/Business/Grand.Business.Messages/Services/MimeMappingService.cs@@ -14,8 +14,7 @@ namespace Grand.Business.Messages.Servicespublic string Map(string filename){- string contentType;- if (!_contentTypeProvider.TryGetContentType(filename, out contentType))+ if (!_contentTypeProvider.TryGetContentType(filename, out var contentType)){contentType = "application/octet-stream";}diff --git a/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs b/src/Business/Grand.Business.Messages/Services/QueuedEmailService.csindex 1c7730806..fdfe76817 100644--- a/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs+++ b/src/Business/Grand.Business.Messages/Services/QueuedEmailService.cs@@ -77,7 +77,7 @@ namespace Grand.Business.Messages.Servicespublic virtual async Task DeleteCustomerEmail(string email){if (email == null)- throw new ArgumentNullException("email");+ throw new ArgumentNullException(nameof(email));var deleteCustomerEmail = _queuedEmailRepository.Table.Where(x => x.To == email);@@ -110,13 +110,8 @@ namespace Grand.Business.Messages.Servicesselect qe;var queuedEmails = query.ToList();//sort by passed identifiers- var sortedQueuedEmails = new List<QueuedEmail>();- foreach (string id in queuedEmailIds)- {- var queuedEmail = queuedEmails.Find(x => x.Id == id);- if (queuedEmail != null)- sortedQueuedEmails.Add(queuedEmail);- }+ var sortedQueuedEmails =+ queuedEmailIds.Select(id => queuedEmails.Find(x => x.Id == id)).Where(queuedEmail => queuedEmail != null).ToList();return await Task.FromResult(sortedQueuedEmails);}@@ -174,16 +169,10 @@ namespace Grand.Business.Messages.Servicesif (maxSendTries > 0)query = query.Where(qe => qe.SentTries < maxSendTries);- if (loadNewest)- {- //load the newest records- query = query.OrderByDescending(qe => qe.CreatedOnUtc);- }- else- {+ //load the newest records+ query = loadNewest ? query.OrderByDescending(qe => qe.CreatedOnUtc) ://load by priority- query = query.OrderByDescending(qe => qe.PriorityId).ThenBy(qe => qe.CreatedOnUtc);- }+ query.OrderByDescending(qe => qe.PriorityId).ThenBy(qe => qe.CreatedOnUtc);return await PagedList<QueuedEmail>.Create(query, pageIndex, pageSize);}diff --git a/src/Business/Grand.Business.Messages/Startup/StartupApplication.cs b/src/Business/Grand.Business.Messages/Startup/StartupApplication.csindex b07e7270a..5c7d54fc3 100644--- a/src/Business/Grand.Business.Messages/Startup/StartupApplication.cs+++ b/src/Business/Grand.Business.Messages/Startup/StartupApplication.cs@@ -19,7 +19,7 @@ namespace Grand.Business.Messages.Startupservices.AddScoped<IMessageProviderService, MessageProviderService>();services.AddScoped<IMessageTokenProvider, MessageTokenProvider>();services.AddScoped<IEmailSender, EmailSender>();- services.AddScoped<IMimeMappingService, MimeMappingService>(x =>+ services.AddScoped<IMimeMappingService, MimeMappingService>(_ =>{var provider = new FileExtensionContentTypeProvider();return new MimeMappingService(provider);