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
Admin panel - minor improvements method GetActiveStore
KrzysztofPajakc0e0ed6f351c
diff --git a/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs b/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.csindex 3e43f5150..4340bc6fc 100644--- a/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc;using Newtonsoft.Json;using System.Linq;using System.Threading.Tasks;+using Microsoft.Extensions.DependencyInjection;namespace Grand.Web.Admin.Controllers{@@ -61,8 +62,11 @@ namespace Grand.Web.Admin.Controllers/// <param name="storeService">Store service</param>/// <param name="workContext">Work context</param>/// <returns>Store ID; 0 if we are in a shared mode</returns>- protected virtual async Task<string> GetActiveStore(IStoreService storeService, IWorkContext workContext)+ protected virtual async Task<string> GetActiveStore(){+ var storeService = HttpContext.RequestServices.GetRequiredService<IStoreService>();+ var workContext = HttpContext.RequestServices.GetRequiredService<IWorkContext>();+var stores = await storeService.GetAllStores();if (stores.Count < 2)return stores.FirstOrDefault().Id;diff --git a/src/Web/Grand.Web.Admin/Controllers/SettingController.cs b/src/Web/Grand.Web.Admin/Controllers/SettingController.csindex 113228b37..9f9e1cc74 100644--- a/src/Web/Grand.Web.Admin/Controllers/SettingController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/SettingController.cs@@ -118,7 +118,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Content(){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var blogSettings = _settingService.LoadSetting<BlogSettings>(storeScope);var newsSettings = _settingService.LoadSetting<NewsSettings>(storeScope);var knowledgebaseSettings = _settingService.LoadSetting<KnowledgebaseSettings>(storeScope);@@ -137,7 +137,7 @@ namespace Grand.Web.Admin.Controllers[HttpPost]public async Task<IActionResult> Content(ContentSettingsModel model){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();//blogvar blogSettings = _settingService.LoadSetting<BlogSettings>(storeScope);blogSettings = model.BlogSettings.ToEntity(blogSettings);@@ -171,7 +171,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Vendor(){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var vendorSettings = _settingService.LoadSetting<VendorSettings>(storeScope);var model = vendorSettings.ToModel();model.AddressSettings.CityEnabled = vendorSettings.CityEnabled;@@ -198,7 +198,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Vendor(VendorSettingsModel model){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var vendorSettings = _settingService.LoadSetting<VendorSettings>(storeScope);vendorSettings = model.ToEntity(vendorSettings);vendorSettings.CityEnabled = model.AddressSettings.CityEnabled;@@ -233,7 +233,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Catalog(){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var catalogSettings = _settingService.LoadSetting<CatalogSettings>(storeScope);var model = catalogSettings.ToModel();model.ActiveStore = storeScope;@@ -243,7 +243,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Catalog(CatalogSettingsModel model){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var catalogSettings = _settingService.LoadSetting<CatalogSettings>(storeScope);catalogSettings = model.ToEntity(catalogSettings);@@ -268,7 +268,7 @@ namespace Grand.Web.Admin.Controllers[HttpPost]public async Task<IActionResult> SortOptionsList(DataSourceRequest command){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var catalogSettings = _settingService.LoadSetting<CatalogSettings>(storeScope);var model = new List<SortOptionModel>();foreach (int option in Enum.GetValues(typeof(ProductSortingEnum)))@@ -290,7 +290,7 @@ namespace Grand.Web.Admin.Controllers[HttpPost]public async Task<IActionResult> SortOptionUpdate(SortOptionModel model){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var catalogSettings = _settingService.LoadSetting<CatalogSettings>(storeScope);catalogSettings.ProductSortingEnumDisplayOrder[model.Id] = model.DisplayOrder;@@ -311,7 +311,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Sales(){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var loyaltyPointsSettings = _settingService.LoadSetting<LoyaltyPointsSettings>(storeScope);var orderSettings = _settingService.LoadSetting<OrderSettings>(storeScope);var shoppingCartSettings = _settingService.LoadSetting<ShoppingCartSettings>(storeScope);@@ -345,7 +345,7 @@ namespace Grand.Web.Admin.Controllers[HttpPost]public async Task<IActionResult> Sales(SalesSettingsModel model){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();if (ModelState.IsValid){@@ -587,7 +587,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Media(){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var mediaSettings = _settingService.LoadSetting<MediaSettings>(storeScope);var model = mediaSettings.ToModel();model.ActiveStore = storeScope;@@ -670,7 +670,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Customer(){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var customerSettings = _settingService.LoadSetting<CustomerSettings>(storeScope);var addressSettings = _settingService.LoadSetting<AddressSettings>(storeScope);@@ -685,7 +685,7 @@ namespace Grand.Web.Admin.Controllers[HttpPost]public async Task<IActionResult> Customer(CustomerSettingsModel model){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var customerSettings = _settingService.LoadSetting<CustomerSettings>(storeScope);var addressSettings = _settingService.LoadSetting<AddressSettings>(storeScope);@@ -711,7 +711,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> GeneralCommon(){var model = new GeneralCommonSettingsModel();- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();model.ActiveStore = storeScope;//store informationvar storeInformationSettings = _settingService.LoadSetting<StoreInformationSettings>(storeScope);@@ -851,7 +851,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> GeneralCommon(GeneralCommonSettingsModel model){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();//store information settingsvar storeInformationSettings = _settingService.LoadSetting<StoreInformationSettings>(storeScope);@@ -999,7 +999,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> PushNotifications(){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var settings = _settingService.LoadSetting<PushNotificationsSettings>(storeScope);var model = new ConfigurationModel {@@ -1022,7 +1022,7 @@ namespace Grand.Web.Admin.Controllers[IgnoreAntiforgeryToken]public async Task<IActionResult> PushNotifications(ConfigurationModel model){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var settings = _settingService.LoadSetting<PushNotificationsSettings>(storeScope);settings.AllowGuestNotifications = model.AllowGuestNotifications;settings.AuthDomain = model.AuthDomain;diff --git a/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs b/src/Web/Grand.Web.Admin/Controllers/ShippingController.csindex 2c617a602..35ef62e75 100644--- a/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs@@ -302,7 +302,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Settings(){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var shippingSettings = _settingService.LoadSetting<ShippingSettings>(storeScope);var model = shippingSettings.ToModel();model.ActiveStore = storeScope;@@ -342,7 +342,7 @@ namespace Grand.Web.Admin.Controllers[FromServices] ICustomerActivityService customerActivityService){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var shippingSettings = _settingService.LoadSetting<ShippingSettings>(storeScope);shippingSettings = model.ToEntity(shippingSettings);diff --git a/src/Web/Grand.Web.Admin/Controllers/TaxController.cs b/src/Web/Grand.Web.Admin/Controllers/TaxController.csindex 087f13a25..8e86ad8ca 100644--- a/src/Web/Grand.Web.Admin/Controllers/TaxController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/TaxController.cs@@ -78,7 +78,7 @@ namespace Grand.Web.Admin.Controllers[HttpPost]public async Task<IActionResult> Providers(DataSourceRequest command){- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var taxSettings = _settingService.LoadSetting<TaxSettings>(storeScope);var taxProviderSettings = _settingService.LoadSetting<TaxProviderSettings>();@@ -135,7 +135,7 @@ namespace Grand.Web.Admin.Controllerspublic async Task<IActionResult> Settings(){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var taxSettings = _settingService.LoadSetting<TaxSettings>(storeScope);var model = taxSettings.ToModel();@@ -184,7 +184,7 @@ namespace Grand.Web.Admin.Controllers[FromServices] ICustomerActivityService customerActivityService){//load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);+ var storeScope = await GetActiveStore();var taxSettings = _settingService.LoadSetting<TaxSettings>(storeScope);taxSettings = model.ToEntity(taxSettings);