Skip to content

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.

Admin - GetActiveStore - Minor changes

KrzysztofPajak71ef8b7aec7b
diff --git a/src/Web/Grand.Web.Admin/Components/StoreScope.cs b/src/Web/Grand.Web.Admin/Components/StoreScope.cs
index f97f40bf7..2516db89b 100644
--- a/src/Web/Grand.Web.Admin/Components/StoreScope.cs
+++ b/src/Web/Grand.Web.Admin/Components/StoreScope.cs
@@ -8,6 +8,8 @@ using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Grand.Business.Common.Interfaces.Directory;
using System.Linq;
+using System.Collections.Generic;
+using Grand.Domain.Stores;
namespace Grand.Web.Admin.Components
{
@@ -52,7 +54,7 @@ namespace Grand.Web.Admin.Components
Name = s.Shortcut
});
}
- model.StoreId = await GetActiveStore(_storeService, _workContext);
+ model.StoreId = await GetActiveStore(allStores);
return View(model);
}
@@ -60,14 +62,14 @@ namespace Grand.Web.Admin.Components
#region Methods
- private async Task<string> GetActiveStore(IStoreService storeService, IWorkContext workContext)
+ private async Task<string> GetActiveStore(IList<Store> stores)
{
//ensure that we have 2 (or more) stores
- if ((await storeService.GetAllStores()).Count < 2)
- return string.Empty;
+ if (stores.Count < 2)
+ return stores.FirstOrDefault().Id;
- var storeId = workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration);
- var store = await storeService.GetStoreById(storeId);
+ var storeId = _workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration);
+ var store = await _storeService.GetStoreById(storeId);
return store != null ? store.Id : "";
}
diff --git a/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs b/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs
index 7b653e8e0..b001c1908 100644
--- a/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs
@@ -10,6 +10,7 @@ using Newtonsoft.Json;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
+using Grand.Business.Common.Interfaces.Directory;
namespace Grand.Web.Admin.Controllers
{
@@ -66,15 +67,25 @@ namespace Grand.Web.Admin.Controllers
{
var storeService = HttpContext.RequestServices.GetRequiredService<IStoreService>();
var workContext = HttpContext.RequestServices.GetRequiredService<IWorkContext>();
+ var groupService = HttpContext.RequestServices.GetRequiredService<IGroupService>();
var stores = await storeService.GetAllStores();
if (stores.Count < 2)
return stores.FirstOrDefault().Id;
- var storeId = workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration);
- var store = await storeService.GetStoreById(storeId);
+ if (await groupService.IsStaff(workContext.CurrentCustomer))
+ {
+ return workContext.CurrentCustomer.StaffStoreId;
+ }
- return store != null ? store.Id : workContext.CurrentStore.Id;
+ var storeId = workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration);
+ if(!string.IsNullOrEmpty(storeId))
+ {
+ var store = await storeService.GetStoreById(storeId);
+ if (store != null)
+ return store.Id;
+ }
+ return stores.FirstOrDefault().Id;
}
/// <summary>
/// Creates a <see cref="T:System.Web.Mvc.JsonResult"/> object that serializes the specified object to JavaScript Object Notation (JSON) format using the content type, content encoding, and the JSON request behavior.
@@ -90,7 +101,7 @@ namespace Grand.Web.Admin.Controllers
public override JsonResult Json(object data)
{
var serializerSettings = new JsonSerializerSettings {
- DateFormatHandling = DateFormatHandling.IsoDateFormat
+ DateFormatHandling = DateFormatHandling.IsoDateFormat
};
return base.Json(data, serializerSettings);
}