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
Improvements/code (#589)
Krzysztof Pajakefdad805e061
diff --git a/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs b/src/Core/Grand.Data/LiteDb/LiteDBRepository.csindex dd42e2236..073249a34 100644--- a/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs+++ b/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs@@ -226,8 +226,8 @@ public class LiteDBRepository<T> : IRepository<T> where T : BaseEntitypropertyInfo?.SetValue(entity, item.Value);}- entity.UpdatedOnUtc = _auditInfoProvider.GetCurrentDateTime();- entity.UpdatedBy = _auditInfoProvider.GetCurrentUser();+ entity!.UpdatedOnUtc = _auditInfoProvider.GetCurrentDateTime();+ entity!.UpdatedBy = _auditInfoProvider.GetCurrentUser();Collection.Update(entity);return Task.CompletedTask;diff --git a/src/Core/Grand.Infrastructure/Caching/Redis/RedisMessageCacheManager.cs b/src/Core/Grand.Infrastructure/Caching/Redis/RedisMessageCacheManager.csindex a1a21d803..6fc492267 100644--- a/src/Core/Grand.Infrastructure/Caching/Redis/RedisMessageCacheManager.cs+++ b/src/Core/Grand.Infrastructure/Caching/Redis/RedisMessageCacheManager.cs@@ -53,12 +53,11 @@ public class RedisMessageCacheManager : MemoryCacheBase, ICacheBase/// Clear cache/// </summary>/// <param name="publisher">publisher</param>- public override Task Clear(bool publisher = true)+ public override async Task Clear(bool publisher = true){- base.Clear();+ await base.Clear(publisher);if (publisher)- _messageBus.PublishAsync(new MessageEvent { Key = "", MessageType = (int)MessageEventType.ClearCache });+ await _messageBus.PublishAsync(new MessageEvent { Key = "", MessageType = (int)MessageEventType.ClearCache });- return Task.CompletedTask;}}\ No newline at end of filediff --git a/src/Modules/Grand.Module.Installer/Services/InstallDataLocaleResources.cs b/src/Modules/Grand.Module.Installer/Services/InstallDataLocaleResources.csindex 674b2dcf2..963c8efcf 100644--- a/src/Modules/Grand.Module.Installer/Services/InstallDataLocaleResources.cs+++ b/src/Modules/Grand.Module.Installer/Services/InstallDataLocaleResources.cs@@ -12,7 +12,7 @@ public partial class InstallationService//save resourcesvar filePath = Path.Combine(_hostingEnvironment.ContentRootPath, "App_Data/Resources/DefaultLanguage.xml");- var localesXml = File.ReadAllText(filePath);+ var localesXml = await File.ReadAllTextAsync(filePath);var xmlDoc = XmlExtensions.LanguageXmlDocument(localesXml);diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtmlindex 0d8ec7805..7248d61ec 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml@@ -176,7 +176,7 @@@if (await groupService.IsAdmin(currentCustomer)){<li>- <a href="@Url.Action("Edit", "Customer", new { currentCustomer.Id, area = Constants.AreaAdmin })">+ <a href="@Url.Action("Edit", "Customer", new { currentCustomer!.Id, area = Constants.AreaAdmin })"><i class="icon-user"></i> @Loc["Admin.Header.Profile"]</a></li>diff --git a/src/Web/Grand.Web.Admin/Controllers/OrderController.cs b/src/Web/Grand.Web.Admin/Controllers/OrderController.csindex 22ea5ecf1..1816ac502 100644--- a/src/Web/Grand.Web.Admin/Controllers/OrderController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/OrderController.cs@@ -945,7 +945,6 @@ public class OrderController(//If we got this far, something failed, redisplay formmodel = await orderViewModelService.PrepareOrderAddressModel(order, address);- model.BillingAddress = model.BillingAddress;return View(model);}diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.csindex f0fc13740..c46296845 100644--- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs@@ -631,7 +631,6 @@ public class ProductController : BaseAdminControllerError(ModelState);model = await _productViewModelService.PrepareRelatedProductModel();- model.ProductId = model.ProductId;return View(model);}@@ -729,7 +728,6 @@ public class ProductController : BaseAdminControllerError(ModelState);model = await _productViewModelService.PrepareSimilarProductModel();- model.ProductId = model.ProductId;return View(model);}@@ -827,7 +825,6 @@ public class ProductController : BaseAdminControllerError(ModelState);model = await _productViewModelService.PrepareBundleProductModel();- model.ProductId = model.ProductId;return View(model);}@@ -915,7 +912,6 @@ public class ProductController : BaseAdminControllerError(ModelState);model = await _productViewModelService.PrepareCrossSellProductModel();- model.ProductId = model.ProductId;return View(model);}@@ -1002,7 +998,6 @@ public class ProductController : BaseAdminControllerError(ModelState);model = await _productViewModelService.PrepareRecommendedProductModel();- model.ProductId = model.ProductId;return View(model);}@@ -1108,7 +1103,6 @@ public class ProductController : BaseAdminControllerError(ModelState);model = await _productViewModelService.PrepareAssociatedProductModel();- model.ProductId = model.ProductId;return View(model);}diff --git a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.csindex 09beb2f31..0daf41d1f 100644--- a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs@@ -104,7 +104,7 @@ public class ShipmentViewModelService : IShipmentViewModelServiceif (prepareProducts)foreach (var shipmentItem in shipment.ShipmentItems){- var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == shipmentItem.OrderItemId);+ var orderItem = order?.OrderItems.FirstOrDefault(x => x.Id == shipmentItem.OrderItemId);if (orderItem == null)continue;@@ -143,8 +143,7 @@ public class ShipmentViewModelService : IShipmentViewModelServiceif (prepareShipmentEvent && !string.IsNullOrEmpty(shipment.TrackingNumber)){- var srcm = _shippingService.LoadShippingRateCalculationProviderBySystemName(- order.ShippingRateProviderSystemName);+ var srcm = _shippingService.LoadShippingRateCalculationProviderBySystemName(order?.ShippingRateProviderSystemName);if (srcm != null &&srcm.IsShippingRateMethodActive(_shippingProviderSettings)){diff --git a/src/Web/Grand.Web.Admin/Validators/Directory/CurrencyValidator.cs b/src/Web/Grand.Web.Admin/Validators/Directory/CurrencyValidator.csindex 0bd7c7a6b..80e08369a 100644--- a/src/Web/Grand.Web.Admin/Validators/Directory/CurrencyValidator.cs+++ b/src/Web/Grand.Web.Admin/Validators/Directory/CurrencyValidator.cs@@ -37,10 +37,9 @@ public class CurrencyValidator : BaseGrandValidator<CurrencyModel>{if (string.IsNullOrEmpty(x))return true;- //create a CultureInfo object- //if "DisplayLocale" is wrong, then exception will be thrown- new CultureInfo(x);- return true;++ var culture = new CultureInfo(x);+ return culture != null;}catch{diff --git a/src/Web/Grand.Web.Admin/Validators/Localization/LanguageValidator.cs b/src/Web/Grand.Web.Admin/Validators/Localization/LanguageValidator.csindex 84392d50d..e270e4902 100644--- a/src/Web/Grand.Web.Admin/Validators/Localization/LanguageValidator.cs+++ b/src/Web/Grand.Web.Admin/Validators/Localization/LanguageValidator.cs@@ -21,8 +21,8 @@ public class LanguageValidator : BaseGrandValidator<LanguageModel>try{//create a CultureInfo object- new CultureInfo(x);- return true;+ var culture = new CultureInfo(x);+ return culture != null;}catch{diff --git a/src/Web/Grand.Web.Admin/Validators/Stores/DomainHostValidator.cs b/src/Web/Grand.Web.Admin/Validators/Stores/DomainHostValidator.csindex ade512552..39ecb4eba 100644--- a/src/Web/Grand.Web.Admin/Validators/Stores/DomainHostValidator.cs+++ b/src/Web/Grand.Web.Admin/Validators/Stores/DomainHostValidator.cs@@ -18,8 +18,8 @@ public class DomainHostValidator : BaseGrandValidator<DomainHostModel>{try{- new Uri(x.Url);- return true;+ var uri = new Uri(x.Url);+ return uri != null;}catch{diff --git a/src/Web/Grand.Web.Admin/Validators/Stores/StoreValidator.cs b/src/Web/Grand.Web.Admin/Validators/Stores/StoreValidator.csindex a5152f8df..3e61b02ef 100644--- a/src/Web/Grand.Web.Admin/Validators/Stores/StoreValidator.cs+++ b/src/Web/Grand.Web.Admin/Validators/Stores/StoreValidator.cs@@ -22,8 +22,8 @@ public class StoreValidator : BaseGrandValidator<StoreModel>{try{- new Uri(x.Url);- return true;+ var uri = new Uri(x.Url);+ return uri != null;}catch{diff --git a/src/Web/Grand.Web.Vendor/Controllers/ProductController.cs b/src/Web/Grand.Web.Vendor/Controllers/ProductController.csindex e23e974fe..c7409c4df 100644--- a/src/Web/Grand.Web.Vendor/Controllers/ProductController.cs+++ b/src/Web/Grand.Web.Vendor/Controllers/ProductController.cs@@ -1067,7 +1067,6 @@ public class ProductController : BaseVendorControllerError(ModelState);model = await _productViewModelService.PrepareAssociatedProductModel();- model.ProductId = model.ProductId;return View(model);}diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchAutoCompleteHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchAutoCompleteHandler.csindex 520e2cfea..d87498018 100644--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchAutoCompleteHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchAutoCompleteHandler.cs@@ -187,12 +187,10 @@ public class GetSearchAutoCompleteHandler : IRequestHandler<GetSearchAutoCompletvar category = await _categoryService.GetCategoryById(item);if (category is not { Published: true }) continue;var allow = true;- if (!_accessControlConfig.IgnoreAcl)- if (!_aclService.Authorize(category, _contextAccessor.WorkContext.CurrentCustomer))- allow = false;- if (!_accessControlConfig.IgnoreStoreLimitations)- if (!_aclService.Authorize(category, storeId))- allow = false;+ if (!_accessControlConfig.IgnoreAcl && !_aclService.Authorize(category, _contextAccessor.WorkContext.CurrentCustomer))+ allow = false;+ if (!_accessControlConfig.IgnoreStoreLimitations && !_aclService.Authorize(category, storeId))+ allow = false;if (!allow) continue;var desc = "";if (_catalogSettings.SearchByDescription)diff --git a/src/Web/Grand.Web/Features/Handlers/Orders/GetShipmentDetailsHandler.cs b/src/Web/Grand.Web/Features/Handlers/Orders/GetShipmentDetailsHandler.csindex 6d3dca97d..0334afe6e 100644--- a/src/Web/Grand.Web/Features/Handlers/Orders/GetShipmentDetailsHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Orders/GetShipmentDetailsHandler.cs@@ -63,8 +63,7 @@ public class GetShipmentDetailsHandler : IRequestHandler<GetShipmentDetails, Shiif (!string.IsNullOrEmpty(request.Shipment.TrackingNumber)){model.TrackingNumber = request.Shipment.TrackingNumber;- var srcm = _shippingService.LoadShippingRateCalculationProviderBySystemName(request.Order- .ShippingRateProviderSystemName);+ var srcm = _shippingService.LoadShippingRateCalculationProviderBySystemName(request.Order.ShippingRateProviderSystemName);if (srcm != null &&srcm.IsShippingRateMethodActive(_shippingProviderSettings)){