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
#nullable enable
using Grand.Domain;
using Grand.Domain.Stores;
using Grand.Infrastructure;
using Grand.Web.AdminShared.Extensions;
using Grand.Web.AdminShared.Interfaces;
namespace Grand.Web.AdminShared.Services;
public class StoreAdminDataScope<TEntity>(IContextAccessor contextAccessor) : IAdminDataScope<TEntity>
where TEntity : BaseEntity, IStoreLinkEntity
{
public Task<bool> HasAccess(TEntity entity)
{
var staffStoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
return Task.FromResult(entity != null && entity.AccessToEntityByStore(staffStoreId));
}
/// <summary>Looser than <see cref="HasAccess"/>: a global entity or one shared across multiple
/// stores (including the staff member's) may be viewed; only an entity limited to stores that
/// exclude the staff member's store is denied. Mirrors Store's original Edit(GET)/CopyProduct
/// behavior (see Grand.Web.Store's ProductController pre-consolidation).</summary>
public Task<bool> CanView(TEntity entity)
{
if (entity is null) return Task.FromResult(false);
var staffStoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var allowed = !entity.LimitedToStores || entity.Stores.Contains(staffStoreId);
return Task.FromResult(allowed);
}
public string? DefaultStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
public string ResourceKeyPrefix => "Admin";
public bool ShowStoreSelector => true;
public string? DefaultVendorId => null;
public bool CanFeatureOnHomepage => true;
}