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
using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Cms;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Domain.Blogs;
using Grand.Domain.Permissions;
using Grand.Domain.Seo;
using Grand.Web.AdminShared.Controllers;
using Grand.Web.AdminShared.Extensions.Mapping;
using Grand.Web.AdminShared.Interfaces;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Localization;
using Grand.Web.Common.Security.Authorization;
using Grand.Web.Store.Extensions;
using Microsoft.AspNetCore.Mvc;
namespace Grand.Web.Store.Controllers;
[AutoValidateAntiforgeryToken]
[Area(Constants.AreaStore)]
[AuthorizeStore]
[AuthorizeMenu]
public class BlogController(
IBlogService blogService,
IBlogViewModelService blogViewModelService,
ILanguageService languageService,
ITranslationService translationService,
IStoreService storeService,
IDateTimeService dateTimeService,
IPictureViewModelService pictureViewModelService,
SeoSettings seoSettings,
IAdminDataScope<BlogPost> postScope,
IAdminDataScope<BlogCategory> categoryScope)
: BaseBlogController(blogService, blogViewModelService, languageService, translationService,
storeService, dateTimeService, pictureViewModelService, seoSettings, postScope, categoryScope)
{
// Re-derived from the original Store BlogController.Edit(GET) - the condition is unusual (warns
// when NOT limited to stores at all, or when limited AND the staff member's store is one of
// several) and easy to get backwards. Identical shape to CategoryController's own
// EditWarningCheck override - same underlying idiom, different entity.
protected override void EditWarningCheck(BlogPost blogPost)
{
if (!blogPost.LimitedToStores ||
(blogPost.Stores.Contains(PostScope.DefaultStoreId) &&
blogPost.Stores.Count > 1))
Warning(TranslationService.GetResource("Admin.Content.Blog.BlogPosts.Permissions"));
}
// Admin has no equivalent action - a genuine Store-only addition, kept on the concrete subclass
// rather than the shared base.
[PermissionAuthorizeAction(PermissionActionName.Preview)]
public async Task<IActionResult> Preview(string id)
{
var blogPost = await BlogService.GetBlogPostById(id);
if (blogPost == null) return RedirectToAction("List");
if (!await PostScope.HasAccess(blogPost)) return RedirectToAction("List");
var model = blogPost.ToModel(DateTimeService);
return View(model);
}
}