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.

Add Blog management functionality to Store area and remove Admin store restrictions (#623)

Copilot4749fb66a032
diff --git a/src/Business/Grand.Business.Cms/Services/BlogService.cs b/src/Business/Grand.Business.Cms/Services/BlogService.cs
index cbf06419b..83d1764a7 100644
--- a/src/Business/Grand.Business.Cms/Services/BlogService.cs
+++ b/src/Business/Grand.Business.Cms/Services/BlogService.cs
@@ -102,7 +102,10 @@ public class BlogService : IBlogService
}
if (!string.IsNullOrEmpty(storeId) && !_accessControlConfig.IgnoreStoreLimitations)
- query = query.Where(b => b.Stores.Contains(storeId) || !b.LimitedToStores);
+ query = from p in query
+ where !p.LimitedToStores || p.Stores.Contains(storeId)
+ select p;
+
if (!string.IsNullOrEmpty(tag)) query = query.Where(x => x.Tags.Contains(tag));
query = query.OrderByDescending(b => b.CreatedOnUtc);
diff --git a/src/Modules/Grand.Module.Installer/Extensions/PermissionExtensions.cs b/src/Modules/Grand.Module.Installer/Extensions/PermissionExtensions.cs
index 0638e318d..4665c1839 100644
--- a/src/Modules/Grand.Module.Installer/Extensions/PermissionExtensions.cs
+++ b/src/Modules/Grand.Module.Installer/Extensions/PermissionExtensions.cs
@@ -213,7 +213,8 @@ public static class PermissionExtensions
StandardPermission.ManageMerchandiseReturns,
StandardPermission.ManageCheckoutAttribute,
StandardPermission.ManageReports,
- StandardPermission.ManageNews
+ StandardPermission.ManageNews,
+ StandardPermission.ManageBlog
]
},
diff --git a/src/Web/Grand.Web.Admin/Controllers/BlogController.cs b/src/Web/Grand.Web.Admin/Controllers/BlogController.cs
index 5dd83c6bf..67792b9bf 100644
--- a/src/Web/Grand.Web.Admin/Controllers/BlogController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/BlogController.cs
@@ -5,9 +5,6 @@ using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Domain.Permissions;
using Grand.Domain.Seo;
-using Grand.Infrastructure;
-using Grand.Web.Admin.Extensions;
-using Grand.Web.AdminShared.Extensions;
using Grand.Web.AdminShared.Extensions.Mapping;
using Grand.Web.AdminShared.Interfaces;
using Grand.Web.AdminShared.Models.Blogs;
@@ -31,8 +28,6 @@ public class BlogController : BaseAdminController
ILanguageService languageService,
ITranslationService translationService,
IStoreService storeService,
- IContextAccessor contextAccessor,
- IGroupService groupService,
IDateTimeService dateTimeService,
IPictureViewModelService pictureViewModelService,
SeoSettings seoSettings)
@@ -42,8 +37,6 @@ public class BlogController : BaseAdminController
_languageService = languageService;
_translationService = translationService;
_storeService = storeService;
- _contextAccessor = contextAccessor;
- _groupService = groupService;
_dateTimeService = dateTimeService;
_pictureViewModelService = pictureViewModelService;
_seoSettings = seoSettings;
@@ -58,8 +51,6 @@ public class BlogController : BaseAdminController
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
private readonly IStoreService _storeService;
- private readonly IContextAccessor _contextAccessor;
- private readonly IGroupService _groupService;
private readonly IDateTimeService _dateTimeService;
private readonly IPictureViewModelService _pictureViewModelService;
private readonly SeoSettings _seoSettings;
@@ -96,7 +87,8 @@ public class BlogController : BaseAdminController
ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
var model = new BlogPostModel {
//default values
- AllowComments = true
+ AllowComments = true,
+ CreateDate = DateTime.UtcNow
};
//locales
await AddLocales(_languageService, model.Locales);
@@ -111,8 +103,6 @@ public class BlogController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var blogPost = await _blogViewModelService.InsertBlogPostModel(model);
Success(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List");
@@ -132,21 +122,6 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- {
- if (!blogPost.LimitedToStores || (blogPost.LimitedToStores &&
- blogPost.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- blogPost.Stores.Count > 1))
- {
- Warning(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Permissions"));
- }
- else
- {
- if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("List");
- }
- }
-
ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
var model = blogPost.ToModel(_dateTimeService);
//locales
@@ -173,15 +148,8 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = blogPost.Id });
-
if (ModelState.IsValid)
{
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
-
blogPost = await _blogViewModelService.UpdateBlogPostModel(model, blogPost);
Success(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Updated"));
@@ -222,10 +190,6 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = blogPost.Id });
-
if (ModelState.IsValid)
{
await _blogService.DeleteBlogPost(blogPost);
@@ -295,7 +259,7 @@ public class BlogController : BaseAdminController
[HttpPost]
public async Task<IActionResult> CategoryList(DataSourceRequest command)
{
- var categories = await _blogService.GetAllBlogCategories(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ var categories = await _blogService.GetAllBlogCategories("");
var gridModel = new DataSourceResult {
Data = categories,
Total = categories.Count
@@ -321,9 +285,6 @@ public class BlogController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
-
var blogCategory = model.ToEntity();
blogCategory.SeName = SeoExtensions.GetSeName(
string.IsNullOrEmpty(blogCategory.SeName) ? blogCategory.Name : blogCategory.SeName,
@@ -352,22 +313,6 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("CategoryList");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- {
- if (!blogCategory.LimitedToStores || (blogCategory.LimitedToStores &&
- blogCategory.Stores.Contains(
- _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- blogCategory.Stores.Count > 1))
- {
- Warning(_translationService.GetResource("Admin.Content.Blog.BlogCategory.Permissions"));
- }
- else
- {
- if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("List");
- }
- }
-
ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
var model = blogCategory.ToModel();
//locales
@@ -388,15 +333,8 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("CategoryList");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("CategoryEdit", new { id = blogCategory.Id });
-
if (ModelState.IsValid)
{
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
-
blogCategory = model.ToEntity(blogCategory);
blogCategory.SeName = SeoExtensions.GetSeName(
string.IsNullOrEmpty(blogCategory.SeName) ? blogCategory.Name : blogCategory.SeName,
@@ -436,10 +374,6 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("CategoryList");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!blogcategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("CategoryEdit", new { id = blogcategory.Id });
-
if (ModelState.IsValid)
{
await _blogService.DeleteBlogCategory(blogcategory);
@@ -488,10 +422,6 @@ public class BlogController : BaseAdminController
if (blogCategory == null)
return ErrorForKendoGridJson("blogCategory no exists");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return ErrorForKendoGridJson("blogCategory no permission");
-
if (ModelState.IsValid)
{
var post = blogCategory.BlogPosts.FirstOrDefault(x => x.Id == id);
@@ -512,12 +442,8 @@ public class BlogController : BaseAdminController
{
var model = new AddBlogPostCategoryModel();
//stores
- var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
-
- model.AvailableStores.Add(new SelectListItem
- { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });
- foreach (var s in (await _storeService.GetAllStores()).Where(x =>
- x.Id == storeId || string.IsNullOrWhiteSpace(storeId)))
+ model.AvailableStores.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });
+ foreach (var s in await _storeService.GetAllStores())
model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id });
model.CategoryId = categoryId;
return View(model);
@@ -529,9 +455,6 @@ public class BlogController : BaseAdminController
{
var gridModel = new DataSourceResult();
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
-
var posts = await _blogService.GetAllBlogPosts(model.SearchStoreId, blogPostName: model.SearchBlogTitle,
pageIndex: command.Page - 1, pageSize: command.PageSize);
gridModel.Data = posts.Select(x => new { x.Id, Name = x.Title });
@@ -550,7 +473,7 @@ public class BlogController : BaseAdminController
if (blogCategory != null)
foreach (var id in model.SelectedBlogPostIds)
{
- var post = _blogService.GetBlogPostById(id);
+ var post = await _blogService.GetBlogPostById(id);
if (post != null)
if (!blogCategory.BlogPosts.Any(x => x.BlogPostId == id))
{
@@ -594,9 +517,6 @@ public class BlogController : BaseAdminController
throw new ArgumentException("No comment found with the specified id");
var blogPost = await _blogService.GetBlogPostById(comment.BlogPostId);
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return ErrorForKendoGridJson("blogPost no permission");
if (ModelState.IsValid)
{
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/BlogPostAddPopup.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/BlogPostAddPopup.cshtml
new file mode 100644
index 000000000..048f14a2d
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/BlogPostAddPopup.cshtml
@@ -0,0 +1,169 @@
+@model AddBlogPostCategoryModel
+@inject AdminAreaSettings adminAreaSettings
+
+@{
+ Layout = "";
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogCategory.AddNewPost"];
+}
+<form id="BlogPostAddPopup" asp-area="@Constants.AreaStore" asp-controller="Blog" asp-action="BlogPostAddPopup" method="post"
+ asp-route-CategoryId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["CategoryId"])"
+ asp-route-btnId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["btnId"])"
+ asp-route-formId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["formId"])">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-sitemap"></i>
+ @Loc["Admin.Content.Blog.BlogCategory.AddNewPost"]
+ </div>
+ </div>
+ <div class="x_content form">
+ <div class="form-horizontal">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="SearchBlogTitle" class="col-sm-4 control-label"/>
+ <div class="col-8 col-md-4 col-sm-4">
+ <admin-input asp-for="SearchBlogTitle"/>
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="offset-md-4 offset-sm-4 col-8 col-md-4 col-sm-4 mt-mobile-10">
+ <div class="btn-group btn-group-devided">
+ <button class="btn btn-success filter-submit" id="search-posts">
+ <i class="fa fa-search"></i> @Loc["Admin.Common.Search"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ </div>
+ </div>
+ </div>
+ <div id="blogposts-grid"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <script>
+ var mfp = $.magnificPopup.instance;
+ $("#BlogPostAddPopup").submit(function (e) {
+ e.preventDefault();
+ var form = $(this);
+ var url = form.attr('action');
+ $.ajax({
+ type: "POST",
+ url: url,
+ data: form.serialize(),
+ success: function (data) {
+ if (data == "") {
+ mfp.close();
+ $('#btnRefreshPosts').click();
+ } else {
+ $.magnificPopup.open({
+ items: {
+ src: data,
+ type: 'inline'
+ },
+ callbacks: {
+ open: function () {
+ $('.mfp-wrap').removeAttr('tabindex');
+ }
+ }
+ });
+ }
+ }
+ });
+ });
+
+ $("#blogposts-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("BlogPostAddPopupList", "Blog", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: additionalData
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors"
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ // Cancel the changes
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ editable: {
+ confirmation: false,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "Id",
+ headerTemplate: "<input id='mastercheckbox' type='checkbox'/>",
+ headerAttributes: { style: "text-align:center" },
+ template: "<input type='checkbox' name='SelectedBlogPostIds' value='#=Id#' class='checkboxGroups' />",
+ attributes: { style: "text-align:center" },
+ width: 50
+ }, {
+ field: "Name",
+ title: "@Loc["Admin.Content.Blog.BlogCategory.Fields.Post"]"
+ }]
+ });
+
+ $('#search-posts').click(function() {
+ var grid = $('#blogposts-grid').data('kendoGrid');
+ grid.dataSource.page(1); //new search. Set page size to 1
+ //grid.dataSource.read(); we already loaded the grid above using "page" function
+ //clear selected checkboxes
+ $('.checkboxGroups').prop('checked', false).change();
+ return false;
+ });
+
+ $("#@Html.IdFor(model => model.SearchBlogTitle)").keydown(function(event) {
+ if (event.keyCode == 13) {
+ $("#search-posts").click();
+ return false;
+ }
+ });
+
+ //wire up checkboxes
+ $('#mastercheckbox').click(function() {
+ $('.checkboxGroups').prop('checked', $(this).is(':checked')).change();
+ });
+
+ $('#blogposts-grid').on('change', 'input[type=checkbox][id!=mastercheckbox]', function(e) {
+ updateMasterCheckbox();
+ });
+
+ function additionalData() {
+ var data = {
+ SearchBlogTitle: $('#@Html.IdFor(model => model.SearchBlogTitle)').val()
+ };
+ addAntiForgeryToken(data);
+ return data;
+ }
+
+ function updateMasterCheckbox() {
+ var numChkBoxes = $('#blogposts-grid input[type=checkbox][id!=mastercheckbox]').length;
+ var numChkBoxesChecked = $('#blogposts-grid input[type=checkbox][id!=mastercheckbox]:checked').length;
+ $('#mastercheckbox').prop('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
+ }
+
+ </script>
+</form>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryCreate.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryCreate.cshtml
new file mode 100644
index 000000000..ee5ec727a
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryCreate.cshtml
@@ -0,0 +1,37 @@
+@model BlogCategoryModel
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogCategory.AddNew"];
+}
+<form asp-area="@Constants.AreaStore" asp-controller="Blog" asp-action="CategoryCreate" method="post">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-comment"></i>
+ @Loc["Admin.Content.Blog.BlogCategory.AddNew"]
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.Content.Blog.BlogCategory.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions">
+ <div class="btn-group btn-group-devided">
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save-continue">
+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]
+ </button>
+ </div>
+ </div>
+ </div>
+ <vc:admin-widget widget-zone="blog_category_buttons" additional-data="null"/>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdateCategory" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryEdit.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryEdit.cshtml
new file mode 100644
index 000000000..21a638b94
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryEdit.cshtml
@@ -0,0 +1,42 @@
+@model BlogCategoryModel
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogCategory.EditBlogCategoryDetails"];
+}
+
+<form asp-area="@Constants.AreaStore" asp-controller="Blog" asp-action="CategoryEdit" method="post" id="category-form">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-comment"></i>
+ @Loc["Admin.Content.Blog.BlogCategory.EditBlogCategoryDetails"]
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.Content.Blog.BlogCategory.BackToList"], "CategoryList")
+ </small>
+ </div>
+ <div class="actions">
+ <div class="btn-group btn-group-devided">
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save-continue">
+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]
+ </button>
+ <span id="blogcategory-delete" class="btn red">
+ <i class="fa fa-trash-o"></i> @Loc["Admin.Common.Delete"]
+ </span>
+ </div>
+ </div>
+ </div>
+ <vc:admin-widget widget-zone="blog_category_buttons" additional-data="Model"/>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdateCategory" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
+<admin-delete-confirmation button-id="blogcategory-delete" action-name="CategoryDelete"/>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryList.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryList.cshtml
new file mode 100644
index 000000000..3b76a7afd
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/CategoryList.cshtml
@@ -0,0 +1,85 @@
+@inject AdminAreaSettings adminAreaSettings
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogCategories"];
+}
+
+<div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-comment"></i>
+ @Loc["Admin.Content.Blog.BlogCategories"]
+ </div>
+ <div class="actions btn-group btn-group-devided">
+ <a href="@Url.Action("CategoryCreate", new { area = Constants.AreaStore })" class="btn green">
+ <i class="fa fa-plus"></i><span class="d-none d-sm-inline"> @Loc["Admin.Common.AddNew"] </span>
+ </a>
+ </div>
+ </div>
+ <div class="x_content form">
+ <div class="form-horizontal">
+ <div class="form-body">
+ <div class="x_content">
+ <div id="blogcategory-grid"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+
+<script>
+ $(document).ready(function () {
+ $("#blogcategory-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("CategoryList", "Blog", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors"
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ // Cancel the changes
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ editable: {
+ confirmation: false,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "Name",
+ title: "@Loc["Admin.Content.Blog.BlogCategory.Fields.Name"]",
+ width: 600,
+ template: '<a class="k-link" href="CategoryEdit/#=Id#">#=kendo.htmlEncode(Name)#</a>',
+ },
+ {
+ field: "DisplayOrder",
+ headerAttributes: { style: "text-align:center" },
+ attributes: { style: "text-align:center" },
+ title: "@Loc["Admin.Content.Blog.BlogCategory.Fields.DisplayOrder"]",
+ width: 100,
+ }]
+ });
+ });
+</script>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Comments.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Comments.cshtml
new file mode 100644
index 000000000..16f1e41a0
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Comments.cshtml
@@ -0,0 +1,112 @@
+@inject AdminAreaSettings adminAreaSettings
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.Comments"];
+ string filterByBlogPostId = ViewBag.FilterByBlogPostId;
+}
+
+<div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption level-caption">
+ <i class="fa fa-comment"></i>
+ @Loc["Admin.Content.Blog.Comments"]
+ </div>
+ </div>
+ <div class="x_content form">
+ <div class="form-horizontal">
+ <div class="form-body">
+ <div class="x_content">
+ <div id="comments-grid"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+
+@{
+ var readUrl = !string.IsNullOrEmpty(filterByBlogPostId) ? Url.Action("Comments", "Blog", new { filterByBlogPostId, area = Constants.AreaStore }) : Url.Action("Comments", "Blog", new { area = Constants.AreaStore });
+}
+<script>
+ $(document).ready(function () {
+ $("#comments-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@readUrl",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ },
+ destroy: {
+ url: "@Html.Raw(Url.Action("CommentDelete", "Blog", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors",
+ model: {
+ id: "Id",
+ fields: {
+ //do not implicitly specify all fields
+ //we do it only for fields which implicitly require it
+ //otherwise, they'll be formatted wrong way
+ CreatedOn: {type: "date" }
+ }
+ }
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ // Cancel the changes
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ editable: {
+ confirmation: true,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "BlogPostTitle",
+ title: "@Loc["Admin.Content.Blog.Comments.Fields.BlogPost"]",
+ width: 200,
+ encoded: false,
+ template: '<a class="k-link" href="@Url.Action("Edit", "Blog", new { area = Constants.AreaStore })/#=BlogPostId#">#:kendo.htmlEncode(BlogPostTitle)#</a>'
+ }, {
+ field: "CustomerId",
+ title: "@Loc["Admin.Content.Blog.Comments.Fields.Customer"]",
+ width: 200,
+ template: '<a class="k-link" href="@Url.Action("Edit", "Customer", new { area = Constants.AreaStore })/#=CustomerId#">#:kendo.htmlEncode(CustomerInfo)#</a>'
+ }, {
+ field: "Comment",
+ title: "@Loc["Admin.Content.Blog.Comments.Fields.Comment"]",
+ encoded: false
+ }, {
+ field: "CreatedOn",
+ title: "@Loc["Admin.Content.Blog.Comments.Fields.CreatedOn"]",
+ width: 200,
+ type: "date",
+ format: "{0:G}"
+ }, {
+ command: { name: "destroy", text: "@Loc["Admin.Common.Delete"]" },
+ title: "@Loc["Admin.Common.Delete"]",
+ width: 100
+ }]
+ });
+ });
+</script>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Create.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Create.cshtml
new file mode 100644
index 000000000..c37419ab5
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Create.cshtml
@@ -0,0 +1,37 @@
+@model BlogPostModel
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogPosts.AddNew"];
+}
+<form asp-area="@Constants.AreaStore" asp-controller="Blog" asp-action="Create" method="post">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-comment"></i>
+ @Loc["Admin.Content.Blog.BlogPosts.AddNew"]
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.Content.Blog.BlogPosts.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions">
+ <div class="btn-group btn-group-devided">
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save-continue">
+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]
+ </button>
+ </div>
+ </div>
+ </div>
+ <vc:admin-widget widget-zone="blog_details_buttons" additional-data="null"/>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdate" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Edit.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Edit.cshtml
new file mode 100644
index 000000000..cb19d53d5
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Edit.cshtml
@@ -0,0 +1,46 @@
+@model BlogPostModel
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogPosts.EditBlogPostDetails"];
+}
+
+<form asp-area="@Constants.AreaStore" asp-controller="Blog" asp-action="Edit" method="post" id="blog-edit">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-comment"></i>
+ @Loc["Admin.Content.Blog.BlogPosts.EditBlogPostDetails"] - @Model.Title
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.Content.Blog.BlogPosts.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions">
+ <div class="btn-group btn-group-devided">
+ <button type="button" onclick="window.open('@Url.RouteUrl("BlogPost", new { Model.SeName })','_blank');" class="btn purple">
+ <i class="fa fa-eye"></i>
+ @Loc["Admin.Common.Preview"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save-continue">
+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]
+ </button>
+ <span id="blogpost-delete" class="btn red">
+ <i class="fa fa-trash-o"></i> @Loc["Admin.Common.Delete"]
+ </span>
+ </div>
+ </div>
+ </div>
+ <vc:admin-widget widget-zone="blog_details_buttons" additional-data="Model"/>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdate" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
+<admin-delete-confirmation button-id="blogpost-delete"/>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/List.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/List.cshtml
new file mode 100644
index 000000000..764550bb4
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/List.cshtml
@@ -0,0 +1,101 @@
+@inject AdminAreaSettings adminAreaSettings
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogPosts"];
+}
+
+<div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-comment"></i>
+ @Loc["Admin.Content.Blog.BlogPosts"]
+ </div>
+ <div class="actions btn-group btn-group-devided">
+ <a href="@Url.Action("Create", new { area = Constants.AreaStore })" class="btn green">
+ <i class="fa fa-plus"></i><span class="d-none d-sm-inline"> @Loc["Admin.Common.AddNew"] </span>
+ </a>
+ </div>
+ </div>
+ <div class="x_content form">
+ <div class="form-horizontal">
+ <div class="form-body">
+ <div class="x_content">
+ <div id="blogpost-grid"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+
+<script>
+ $(document).ready(function () {
+ $("#blogpost-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("List", "Blog", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors"
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ // Cancel the changes
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ editable: {
+ confirmation: false,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "Title",
+ title: "@Loc["Admin.Content.Blog.BlogPosts.Fields.Title"]",
+ width: 400,
+ template: '<a class="k-link" href="Edit/#=Id#">#=kendo.htmlEncode(Title)#</a>',
+ }, {
+ field: "Comments",
+ title: "@Loc["Admin.Content.Blog.BlogPosts.Fields.Comments"]",
+ width: 200,
+ template: '<a class="k-link" href="Comments?filterByBlogPostId=#=Id#">@Loc["Admin.Content.Blog.BlogPosts.Fields.Comments"] - #=Comments# </a>'
+ }, {
+ field: "StartDate",
+ title: "@Loc["Admin.Content.Blog.BlogPosts.Fields.StartDate"]",
+ width: 150,
+ type: "date",
+ format: "{0:G}"
+ }, {
+ field: "EndDate",
+ title: "@Loc["Admin.Content.Blog.BlogPosts.Fields.EndDate"]",
+ width: 150,
+ type: "date",
+ format: "{0:G}"
+ }, {
+ field: "CreatedOn",
+ title: "@Loc["Admin.Content.Blog.BlogPosts.Fields.CreatedOn"]",
+ width: 200,
+ type: "date",
+ format: "{0:G}"
+ }]
+ });
+ });
+</script>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabComments.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabComments.cshtml
new file mode 100644
index 000000000..1604773de
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabComments.cshtml
@@ -0,0 +1,93 @@
+@model BlogPostModel
+@inject AdminAreaSettings adminAreaSettings
+@if (!string.IsNullOrEmpty(Model.Id))
+{
+ <div class="panel panel-default">
+ <vc:admin-widget widget-zone="blog_details_comments_top" additional-data="Model"/>
+ <div class="panel-body">
+ <div id="comments-grid"></div>
+ </div>
+ <vc:admin-widget widget-zone="blog_details_comments_bottom" additional-data="Model"/>
+ </div>
+
+ <script>
+ $(document).ready(function () {
+ $("#comments-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Url.Action("Comments", "Blog", new { filterByBlogPostId = Model.Id, area = Constants.AreaStore })",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ },
+ destroy: {
+ url: "@Html.Raw(Url.Action("CommentDelete", "Blog", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors",
+ model: {
+ id: "Id",
+ fields: {
+ //do not implicitly specify all fields
+ //we do it only for fields which implicitly require it
+ //otherwise, they'll be formatted wrong way
+ CreatedOn: {type: "date" }
+ }
+ }
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ // Cancel the changes
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ editable: {
+ confirmation: true,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "CustomerId",
+ title: "@Loc["Admin.Content.Blog.Comments.Fields.Customer"]",
+ width: 200,
+ template: '<a class="k-link" href="@Url.Action("Edit", "Customer", new { area = Constants.AreaStore })/#=CustomerId#">#:kendo.htmlEncode(CustomerInfo)#</a>'
+ }, {
+ field: "Comment",
+ title: "@Loc["Admin.Content.Blog.Comments.Fields.Comment"]",
+ encoded: false
+ }, {
+ field: "CreatedOn",
+ title: "@Loc["Admin.Content.Blog.Comments.Fields.CreatedOn"]",
+ width: 200,
+ type: "date",
+ format: "{0:G}"
+ }, {
+ command: { name: "destroy", text: "@Loc["Admin.Common.Delete"]" },
+ title: "@Loc["Admin.Common.Delete"]",
+ width: 100
+ }]
+ });
+ });
+ </script>
+}
+else
+{
+ <div class="note note-info">
+ @Loc["Admin.Content.Blog.BlogPosts.SaveBeforeEdit"]
+ </div>
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabInfo.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabInfo.cshtml
new file mode 100644
index 000000000..2a8f9bf11
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabInfo.cshtml
@@ -0,0 +1,170 @@
+@using System.Text.Encodings.Web
+@using Microsoft.AspNetCore.Mvc.Razor
+@model BlogPostModel
+@inject IBlogService blogService
+
+<script>
+ @{
+ var blogTags = await blogService.GetAllBlogPostTags("", true);
+ var blogTagsSb = new StringBuilder();
+ blogTagsSb.Append("var initialBlogTags = [");
+ for (var i = 0; i < blogTags.Count; i++)
+ {
+ var tag = blogTags[i];
+ blogTagsSb.Append("'");
+ blogTagsSb.Append(JavaScriptEncoder.Default.Encode(string.IsNullOrEmpty(tag.Name) ? "" : tag.Name));
+ blogTagsSb.Append("'");
+ if (i != blogTags.Count - 1)
+ {
+ blogTagsSb.Append(",");
+ }
+ }
+
+ blogTagsSb.Append("]");
+ }
+
+ //tags
+ $(document).ready(function () {
+ @Html.Raw(blogTagsSb.ToString())
+ $("#@Html.IdFor(model => model.Tags)").tagEditor({
+ autocomplete: {
+ delay: 0,
+ position: { collision: 'flip' },
+ source: initialBlogTags
+ },
+ delimiter: ',',
+ placeholder: '@Loc["Admin.Content.Blog.BlogPosts.Fields.Tags.Placeholder"]'
+ });
+ });
+</script>
+
+@{
+ Func<int, HelperResult>
+ template = @<div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].Title"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="@Model.Locales[item].Title"/>
+ <span asp-validation-for="@Model.Locales[item].Title"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].BodyOverview"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-textarea asp-for="@Model.Locales[item].BodyOverview"></admin-textarea>
+ <span asp-validation-for="@Model.Locales[item].BodyOverview"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Locales[item].Body"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="@Model.Locales[item].Body" asp-template="Editor"/>
+ <span asp-validation-for="Locales[item].Body"></span>
+ </div>
+ </div>
+ <input type="hidden" asp-for="@Model.Locales[item].LanguageId"/>
+ </div>;
+}
+
+<div class="form-horizontal">
+ <vc:admin-widget widget-zone="blog_details_info_top" additional-data="Model"/>
+ <localized-editor localized-template="@template" name="blogpost-info-localized" language-ids="@Model.Locales.Select(c => c.LanguageId).ToList()">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="Title"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Title"/>
+ <span asp-validation-for="Title"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="BodyOverview"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-textarea asp-for="BodyOverview"></admin-textarea>
+ <span asp-validation-for="BodyOverview"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Body"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Body" asp-template="Editor"/>
+ <span asp-validation-for="Body"></span>
+ </div>
+ </div>
+ </div>
+ </localized-editor>
+ <div class="form-group">
+ @{
+ ViewData["Reference"] = "Blog";
+ ViewData["ObjectId"] = Model.Id;
+ }
+ <admin-label asp-for="PictureId"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="PictureId"/>
+ <span asp-validation-for="PictureId"></span>
+ @if (!string.IsNullOrEmpty(Model.PictureId))
+ {
+ <label class="control-label">
+ <a class='k-link picturelink' href='@Url.Action("PicturePopup", "Blog", new { area = Constants.AreaStore })/?blogpostId=@(Model.Id)'>@Loc["Admin.Common.Picture.Attributes"]</a>
+ </label>
+ <script>
+ $(document).ready(function () {
+ $('.picturelink').magnificPopup({
+ type: 'ajax',
+ settings: { cache: false, async: false },
+ midClick: true,
+ callbacks:
+ {
+ parseAjax: function (mfpResponse) {
+ mfpResponse.data = $('<div></div>').html(mfpResponse.data);
+ },
+ ajaxContentAdded: function () {
+ $('.mfp-wrap').removeAttr('tabindex');
+ }
+ }
+ });
+ });
+ </script>
+ }
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="AllowComments"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
+ <admin-input asp-for="AllowComments"/>
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="AllowComments"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Tags"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Tags"/>
+ <span asp-validation-for="Tags"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="CreateDate"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="CreateDate"/>
+ <span asp-validation-for="CreateDate"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="StartDate"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="StartDate"/>
+ <span asp-validation-for="StartDate"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="EndDate"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="EndDate"/>
+ <span asp-validation-for="EndDate"></span>
+ </div>
+ </div>
+ <vc:admin-widget widget-zone="blog_details_info_bottom" additional-data="Model"/>
+</div>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabProducts.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabProducts.cshtml
new file mode 100644
index 000000000..cf5cb85cb
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabProducts.cshtml
@@ -0,0 +1,128 @@
+@model BlogPostModel
+@inject AdminAreaSettings adminAreaSettings
+@if (!string.IsNullOrEmpty(Model.Id))
+{
+ <div class="panel panel-default">
+ <vc:admin-widget widget-zone="blog_details_product_top" additional-data="Model"/>
+ <div class="panel-body">
+ <div id="product-grid"></div>
+ </div>
+ <div class="panel-footer">
+ <a id="btnAddNewProduct" href="@(Url.Action("ProductAddPopup", "Blog", new { blogPostId = Model.Id, btnId = "btnRefreshProducts", formId = "blog-edit", area = Constants.AreaStore }))" class="k-button"><i class="fa fa-plus"></i>&nbsp;@Loc["Admin.Content.Blog.BlogPosts.Products.AddNew"]</a>
+ <input type="button" id="btnRefreshProducts" style="display: none"/>
+ </div>
+ <vc:admin-widget widget-zone="blog_details_product_bottom" additional-data="Model"/>
+ </div>
+ <script>
+ $(document).ready(function () {
+ $('#btnAddNewProduct').magnificPopup({
+ type: 'ajax',
+ settings: { cache: false, async: false },
+ midClick: true,
+ callbacks: {
+ parseAjax: function (mfpResponse) {
+ mfpResponse.data = $('<div></div>').html(mfpResponse.data);
+ },
+ ajaxContentAdded: function () {
+ $('.mfp-wrap').removeAttr('tabindex');
+ }
+ }
+ });
+ $("#product-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("Products", "Blog", new { blogPostId = Model.Id, area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ },
+ update: {
+ url:"@Html.Raw(Url.Action("UpdateProduct", "Blog", new { blogPostId = Model.Id, area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ },
+ destroy: {
+ url: "@Html.Raw(Url.Action("DeleteProduct", "Blog", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors",
+ model: {
+ id: "Id",
+ fields: {
+ ProductName: {editable: false, type: "string" },
+ DisplayOrder: {editable: true, type: "number", format:"{0:n2}" },
+ }
+ }
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ // Cancel the changes
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ editable: {
+ confirmation: false,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "ProductName",
+ title: "@Loc["Admin.Content.Blog.Product.Fields.ProductName"]",
+ width: 300,
+ template: '<a href="@Url.Action("Edit", "Product", new { area = Constants.AreaStore })/#=ProductId#" target="_blank">#=kendo.htmlEncode(ProductName)#</a>'
+ }, {
+ field: "DisplayOrder",
+ title: "@Loc["Admin.Content.Blog.Product.Fields.DisplayOrder"]",
+ width: 100,
+ type: "number",
+
+ }, {
+ command: [{
+ name: "edit",
+ text: {
+ edit: "@Loc["Admin.Common.Edit"]",
+ update: "@Loc["Admin.Common.Update"]",
+ cancel: "@Loc["Admin.Common.Cancel"]"} }, {
+ name: "destroy",
+ text: "@Loc["Admin.Common.Delete"]"
+ }],
+ width: 200
+ }]
+ });
+ });
+ </script>
+ <script>
+ $(document).ready(function () {
+ $('#btnRefreshProducts').click(function () {
+ //refresh grid
+ var grid = $("#product-grid").data('kendoGrid');
+ grid.dataSource.read();
+
+ //return false to don't reload a page
+ return false;
+ });
+ });
+ </script>
+}
+else
+{
+ <div class="note note-info">
+ @Loc["Admin.Content.Blog.BlogPosts.SaveBeforeEdit"]
+ </div>
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabSeo.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabSeo.cshtml
new file mode 100644
index 000000000..1fef5cb5b
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.TabSeo.cshtml
@@ -0,0 +1,75 @@
+@using Microsoft.AspNetCore.Mvc.Razor
+@model BlogPostModel
+
+<vc:admin-widget widget-zone="blog_details_seo_top" additional-data="Model"/>
+@{
+ Func<int, HelperResult>
+ template = @<div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].MetaKeywords"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="@Model.Locales[item].MetaKeywords"/>
+ <span asp-validation-for="@Model.Locales[item].MetaKeywords"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].MetaDescription"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-textarea asp-for="@Model.Locales[item].MetaDescription"></admin-textarea>
+ <span asp-validation-for="@Model.Locales[item].MetaDescription"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].MetaTitle"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="@Model.Locales[item].MetaTitle"/>
+ <span asp-validation-for="@Model.Locales[item].MetaTitle"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].SeName"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="@Model.Locales[item].SeName"/>
+ <span asp-validation-for="@Model.Locales[item].SeName"></span>
+ </div>
+ </div>
+ <input type="hidden" asp-for="@Model.Locales[item].LanguageId"/>
+ </div>;
+}
+
+<div class="form-horizontal">
+ <localized-editor localized-template="@template" name="blogpost-seo-localized" language-ids="@Model.Locales.Select(c => c.LanguageId).ToList()">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="MetaKeywords"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="MetaKeywords"/>
+ <span asp-validation-for="MetaKeywords"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="MetaDescription"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-textarea asp-for="MetaDescription"></admin-textarea>
+ <span asp-validation-for="MetaDescription"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="MetaTitle"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="MetaTitle"/>
+ <span asp-validation-for="MetaTitle"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="SeName"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SeName"/>
+ <span asp-validation-for="SeName"></span>
+ </div>
+ </div>
+ </div>
+ </localized-editor>
+</div>
+
+<vc:admin-widget widget-zone="blog_details_seo_bottom" additional-data="Model"/>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.cshtml
new file mode 100644
index 000000000..734865b7e
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdate.cshtml
@@ -0,0 +1,50 @@
+@model BlogPostModel
+
+<div asp-validation-summary="All"></div>
+<input asp-for="Id" type="hidden"/>
+<input id="active-menu-item" type="hidden" value="/@Constants.AreaStore/Blog/List"/>
+
+<admin-tabstrip name="blog-post-edit">
+ <items>
+ <tabstrip-item text="@Loc["Admin.Content.Blog.BlogPosts.Info"]" tab-index="0">
+ <content>
+ <div>
+ <partial name="Partials/CreateOrUpdate.TabInfo" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ <tabstrip-item text="@Loc["Admin.Common.SEO"]" tab-index="1">
+ <content>
+ <div>
+ <partial name="Partials/CreateOrUpdate.TabSeo" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ <tabstrip-item text="@Loc["Admin.Content.Blog.BlogPosts.Products"]" tab-index="2">
+ <content>
+ <div>
+ <partial name="Partials/CreateOrUpdate.TabProducts" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ <tabstrip-item text="@Loc["Admin.Content.Blog.BlogPosts.Comments"]" tab-index="3">
+ <content>
+ <div>
+ <partial name="Partials/CreateOrUpdate.TabComments" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ <tabstrip-item text="@Loc["Admin.Common.UserFields.Tab"]" tab-index="4">
+ <content>
+ <div>
+ <partial name="Partials/UserFields" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ <vc:admin-widget widget-zone="blog_details_tabs" additional-data="Model"/>
+ </items>
+</admin-tabstrip>
+
+<link rel="stylesheet" type="text/css" asp-src="@(Grand.SharedUIResources.Constants.WwwRoot)/administration/tagEditor/jquery.tag-editor.css"/>
+<script asp-location="Footer" asp-src="@(Grand.SharedUIResources.Constants.WwwRoot)/administration/tagEditor/jquery.tag-editor.min.js"></script>
+<script asp-location="Footer" asp-src="@(Grand.SharedUIResources.Constants.WwwRoot)/administration/tagEditor/jquery.caret.min.js"></script>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.Posts.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.Posts.cshtml
new file mode 100644
index 000000000..181e70aeb
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.Posts.cshtml
@@ -0,0 +1,112 @@
+@model BlogCategoryModel
+
+@inject AdminAreaSettings adminAreaSettings
+@if (!string.IsNullOrEmpty(Model.Id))
+{
+ <div class="panel panel-default">
+ <div class="panel-body">
+ <div id="posts-grid"></div>
+ </div>
+ <div class="panel-footer">
+ <a id="btnAddNewPost" href="@(Url.Action("BlogPostAddPopup", "Blog", new { categoryId = Model.Id, btnId = "btnRefreshPosts", formId = "category-form", area = Constants.AreaStore }))" class="k-button"><i class="fa fa-plus"></i>&nbsp;@Loc["Admin.Content.Blog.BlogCategory.AddNewPost"]</a>
+ <input type="submit" id="btnRefreshPosts" style="display: none"/>
+ </div>
+ </div>
+ <script>
+ $(document).ready(function () {
+ $('#btnAddNewPost').magnificPopup({
+ type: 'ajax',
+ settings: { cache: false, async: false },
+ midClick: true,
+ callbacks: {
+ parseAjax: function (mfpResponse) {
+ mfpResponse.data = $('<div></div>').html(mfpResponse.data);
+ },
+ ajaxContentAdded: function () {
+ $('.mfp-wrap').removeAttr('tabindex');
+ }
+ }
+ });
+ $("#posts-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("CategoryPostList", "Blog", new { categoryId = Model.Id, area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ },
+ destroy: {
+ url: "@Html.Raw(Url.Action("CategoryPostDelete", "Blog", new { categoryId = Model.Id, area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors",
+ model: {
+ id: "Id",
+ fields: {
+ Name: {editable: false, type: "string" },
+ BlogPostId: {editable: false, type: "string" }
+ }
+ }
+ },
+ requestEnd: function(e) {
+ if(e.type=="update") {
+ this.read();
+ }
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ // Cancel the changes
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ editable: {
+ confirmation: false,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "Name",
+ title: "@Loc["Admin.Content.Blog.BlogCategory.Fields.Post"]",
+ template: '<a class="k-link" href="@Url.Action("Edit", "Blog", new { area = Constants.AreaStore })/#=BlogPostId#">#=kendo.htmlEncode(Name)#</a>',
+ },{
+ command: [{
+ name: "destroy",
+ text: "@Loc["Admin.Common.Delete"]"
+ }],
+ }]
+ });
+ });
+ </script>
+ <script>
+ $(document).ready(function () {
+ $('#btnRefreshPosts').click(function () {
+ //refresh grid
+ var grid = $("#posts-grid").data('kendoGrid');
+ grid.dataSource.read();
+ //return false to don't reload a page
+ return false;
+ });
+ });
+ </script>
+}
+else
+{
+ <div class="note note-info">
+ @Loc["Admin.Content.Blog.BlogCategory.SaveBeforeEdit"]
+ </div>
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.TabInfo.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.TabInfo.cshtml
new file mode 100644
index 000000000..31a0a955c
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.TabInfo.cshtml
@@ -0,0 +1,47 @@
+@using Microsoft.AspNetCore.Mvc.Razor
+@model BlogCategoryModel
+
+
+@{
+ Func<int, HelperResult>
+ template = @<div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].Name"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="@Model.Locales[item].Name"/>
+ <span asp-validation-for="@Model.Locales[item].Name"></span>
+ </div>
+ </div>
+ <input type="hidden" asp-for="@Model.Locales[item].LanguageId"/>
+ </div>;
+}
+
+<div class="form-horizontal">
+ <vc:admin-widget widget-zone="blog_category_info_top" additional-data="Model"/>
+ <localized-editor localized-template="@template" name="blogcategory-info-localized" language-ids="@Model.Locales.Select(c => c.LanguageId).ToList()">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="Name"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Name"/>
+ <span asp-validation-for="Name"></span>
+ </div>
+ </div>
+ </div>
+ </localized-editor>
+ <div class="form-group">
+ <admin-label asp-for="SeName"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SeName"/>
+ <span asp-validation-for="SeName"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="DisplayOrder"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="DisplayOrder"/>
+ <span asp-validation-for="DisplayOrder"></span>
+ </div>
+ </div>
+ <vc:admin-widget widget-zone="blog_category_info_bottom" additional-data="Model"/>
+</div>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.cshtml
new file mode 100644
index 000000000..2271f47aa
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Partials/CreateOrUpdateCategory.cshtml
@@ -0,0 +1,23 @@
+@model BlogCategoryModel
+
+<div asp-validation-summary="All"></div>
+<input asp-for="Id" type="hidden"/>
+<admin-tabstrip name="blog-category-edit">
+ <items>
+ <tabstrip-item text="@Loc["Admin.Content.Blog.BlogCategory.Info"]" tab-index="0">
+ <content>
+ <div>
+ <partial name="Partials/CreateOrUpdateCategory.TabInfo" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ <tabstrip-item text="@Loc["Admin.Content.Blog.BlogCategory.Posts"]" tab-index="1">
+ <content>
+ <div>
+ <partial name="Partials/CreateOrUpdateCategory.Posts" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ <vc:admin-widget widget-zone="blog_category_details_tabs" additional-data="Model"/>
+ </items>
+</admin-tabstrip>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Preview.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Preview.cshtml
new file mode 100644
index 000000000..7181f83b4
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Preview.cshtml
@@ -0,0 +1,45 @@
+@model BlogPostModel
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogPosts.Preview"];
+ Layout = Constants.LayoutStore;
+}
+
+<div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-blog"></i>
+ @Loc["Admin.Content.Blog.BlogPosts.Preview"] - @Model.Title
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.Content.Blog.BlogPosts.BackToList"], "List")
+ </small>
+ </div>
+ </div>
+ <div class="x_content">
+ <div class="blog-preview">
+ <h1>@Model.Title</h1>
+ @if (!string.IsNullOrEmpty(Model.BodyOverview))
+ {
+ <div class="overview">
+ @Html.Raw(Model.BodyOverview)
+ </div>
+ }
+ @if (!string.IsNullOrEmpty(Model.Body))
+ {
+ <div class="body">
+ @Html.Raw(Model.Body)
+ </div>
+ }
+ @if (!string.IsNullOrEmpty(Model.Tags))
+ {
+ <div class="tags mt-3">
+ <strong>@Loc["Admin.Content.Blog.BlogPosts.Fields.Tags"]:</strong> @Model.Tags
+ </div>
+ }
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/ProductAddPopup.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/ProductAddPopup.cshtml
new file mode 100644
index 000000000..d161932ad
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/ProductAddPopup.cshtml
@@ -0,0 +1,221 @@
+@model BlogProductModel.AddProductModel
+@inject AdminAreaSettings adminAreaSettings
+@{
+ Layout = "";
+ //page title
+ ViewBag.Title = Loc["Admin.Content.Blog.BlogPosts.Products.AddNew"];
+}
+
+<form id="ProductAddPopup" asp-area="@Constants.AreaStore" asp-controller="Blog" asp-action="ProductAddPopup" method="post"
+ asp-route-BlogPostId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["BlogPostId"])"
+ asp-route-btnId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["btnId"])"
+ asp-route-formId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["formId"])">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit popup-window">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-sitemap"></i>
+ @Loc["Admin.Content.Blog.BlogPosts.Products.AddNew"]
+ </div>
+ </div>
+ <div class="x_content form">
+ <div class="form-horizontal">
+ <div class="form-body">
+ <div class="main-header col-12 px-0">
+ <div class="row align-items-end">
+ <div class="col-md col-ms-12 col-12">
+ <div class="form-group mb-0">
+ <admin-label asp-for="SearchProductName" class="control-label"/>
+ <admin-input asp-for="SearchProductName"/>
+ </div>
+ </div>
+ <div class="col-md-auto col-sm-12 col-12">
+ <div class="form-actions">
+ <div class="btn-group btn-group-devided">
+ <button class="btn btn-success filter-submit" id="search-products">
+ <i class="fa fa-search"></i>&nbsp; @Loc["Admin.Common.Search"]
+ </button>
+ <button class="btn btn-info" type="button" data-toggle="collapse" data-target="#filterCollapse" aria-expanded="false" aria-controls="filterCollapse">
+ <i class="fa fa-filter"></i>&nbsp; @Loc["Admin.Common.Filters"]
+ </button>
+ </div>
+ <button class="btn btn-success" type="submit" name="save"><i class="fa fa-check"></i> &nbsp; @Loc["Admin.Common.Save"] </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="collapse" id="filterCollapse">
+ <div class="drop-filters-container">
+ <div class="form-group">
+ <admin-label asp-for="SearchCategoryId" class="col-sm-3 control-label"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SearchCategoryId"/>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="SearchCollectionId" class="col-sm-3 control-label"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SearchCollectionId"/>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="SearchBrandId" class="col-sm-3 control-label"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SearchBrandId"/>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="SearchProductTypeId" class="col-sm-3 control-label"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-select asp-for="SearchProductTypeId" asp-items="Model.AvailableProductTypes"/>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div id="products-grid"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <script>
+ var mfp = $.magnificPopup.instance;
+ $("#ProductAddPopup").submit(function (e) {
+ e.preventDefault();
+ var form = $(this);
+ var url = form.attr('action');
+ $.ajax({
+ type: "POST",
+ url: url,
+ data: form.serialize(),
+ success: function (data) {
+ if (data == "") {
+ mfp.close();
+ $('#btnRefreshProducts').click();
+ } else {
+ $.magnificPopup.open({
+ items: {
+ src: data,
+ type: 'inline'
+ },
+ callbacks: {
+ open: function () {
+ $('.mfp-wrap').removeAttr('tabindex');
+ }
+ }
+ });
+ }
+ }
+ });
+ });
+
+ $('.extend-collapse').hide();
+ $('.filter-extend-button').click(function () {
+ $('.extend-collapse').toggle("slow");
+ $('.filter-text-close').toggle();
+ });
+
+ $("#products-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("ProductAddPopupList", "Blog", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: additionalData
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors"
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ // Cancel the changes
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ editable: {
+ confirmation: false,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "Id",
+ title: "@Loc["Admin.Common.Check"]",
+ headerTemplate: "<input id='mastercheckbox' type='checkbox'/>",
+ headerAttributes: { style: "text-align:center" },
+ template: "<input type='checkbox' name='SelectedProductIds' value='#=Id#' class='checkboxGroups' />",
+ attributes: { style: "text-align:center" },
+ width: 50
+ }, {
+ field: "Name",
+ title: "@Loc["Admin.Catalog.Products.Fields.Name"]"
+ }, {
+ field: "Published",
+ title: "@Loc["Admin.Catalog.Products.Fields.Published"]",
+ width: 100,
+ headerAttributes: { style: "text-align:center" },
+ attributes: { style: "text-align:center" },
+ template: '# if(Published) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
+ }]
+ });
+
+ $('#search-products').click(function() {
+ var grid = $('#products-grid').data('kendoGrid');
+ grid.dataSource.page(1); //new search. Set page size to 1
+ //grid.dataSource.read(); we already loaded the grid above using "page" function
+ //clear selected checkboxes
+ $('.checkboxGroups').prop('checked', false).change();
+ return false;
+ });
+
+ $("#@Html.IdFor(model => model.SearchProductName)").keydown(function(event) {
+ if (event.keyCode == 13) {
+ $("#search-products").click();
+ return false;
+ }
+ });
+
+ //wire up checkboxes
+ $('#mastercheckbox').click(function() {
+ $('.checkboxGroups').prop('checked', $(this).is(':checked')).change();
+ });
+
+ $('#products-grid').on('change', 'input[type=checkbox][id!=mastercheckbox]', function(e) {
+ updateMasterCheckbox();
+ });
+
+ function additionalData() {
+ var data = {
+ SearchProductName: $('#@Html.IdFor(model => model.SearchProductName)').val(),
+ SearchCategoryId: $('#SearchCategoryId').val(),
+ SearchBrandId: $('#SearchBrandId').val(),
+ SearchCollectionId: $('#SearchCollectionId').val(),
+ SearchProductTypeId: $('#SearchProductTypeId').val()
+ };
+ addAntiForgeryToken(data);
+ return data;
+ }
+
+ function updateMasterCheckbox() {
+ var numChkBoxes = $('#products-grid input[type=checkbox][id!=mastercheckbox]').length;
+ var numChkBoxesChecked = $('#products-grid input[type=checkbox][id!=mastercheckbox]:checked').length;
+ $('#mastercheckbox').prop('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
+ }
+
+ </script>
+</form>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Product/BulkEdit.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Product/BulkEdit.cshtml
index 49e251ba9..38ae21002 100644
--- a/src/Web/Grand.Web.Store/Areas/Store/Views/Product/BulkEdit.cshtml
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Product/BulkEdit.cshtml
@@ -289,8 +289,7 @@
SearchCategoryId: $('#SearchCategoryId').val(),
SearchBrandId: $('#SearchBrandId').val(),
SearchCollectionId: $('#SearchCollectionId').val(),
- SearchProductTypeId: $('#SearchProductTypeId').val(),
- SearchStoreId: $('#SearchStoreId').val(),
+ SearchProductTypeId: $('#SearchProductTypeId').val()
};
addAntiForgeryToken(data);
return data;
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/_ViewImports.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/_ViewImports.cshtml
index d9c332025..4d17948f3 100644
--- a/src/Web/Grand.Web.Store/Areas/Store/Views/_ViewImports.cshtml
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/_ViewImports.cshtml
@@ -30,6 +30,7 @@
@using Grand.Web.AdminShared.Models.Customers
@using Grand.Web.AdminShared.Models.Cms
@using Grand.Web.AdminShared.Models.News
+@using Grand.Web.AdminShared.Models.Blogs
@inject LocService Loc
@inject IEnumTranslationService EnumTranslationService
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Controllers/BlogController.cs b/src/Web/Grand.Web.Store/Controllers/BlogController.cs
new file mode 100644
index 000000000..7cac921c1
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Controllers/BlogController.cs
@@ -0,0 +1,719 @@
+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.Domain.Blogs;
+using Grand.Domain.Permissions;
+using Grand.Domain.Seo;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Extensions;
+using Grand.Web.AdminShared.Extensions.Mapping;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Blogs;
+using Grand.Web.AdminShared.Models.Common;
+using Grand.Web.Common.DataSource;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Store.Controllers;
+
+[PermissionAuthorize(PermissionSystemName.Blog)]
+public class BlogController : BaseStoreController
+{
+ #region Constants
+
+ private const string NoAccessToBlogPostMessage = "You don't have access to this blog post";
+ private const string NoAccessToBlogCategoryMessage = "You don't have access to this blog category";
+ private const string CategoryListAction = "CategoryList";
+
+ #endregion
+
+ #region Constructors
+
+ public BlogController(
+ IBlogService blogService,
+ IBlogViewModelService blogViewModelService,
+ ILanguageService languageService,
+ ITranslationService translationService,
+ IContextAccessor contextAccessor,
+ IDateTimeService dateTimeService,
+ IPictureViewModelService pictureViewModelService,
+ SeoSettings seoSettings)
+ {
+ _blogService = blogService;
+ _blogViewModelService = blogViewModelService;
+ _languageService = languageService;
+ _translationService = translationService;
+ _contextAccessor = contextAccessor;
+ _dateTimeService = dateTimeService;
+ _pictureViewModelService = pictureViewModelService;
+ _seoSettings = seoSettings;
+ }
+
+ #endregion
+
+ #region Fields
+
+ private readonly IBlogService _blogService;
+ private readonly IBlogViewModelService _blogViewModelService;
+ private readonly ILanguageService _languageService;
+ private readonly ITranslationService _translationService;
+ private readonly IContextAccessor _contextAccessor;
+ private readonly IDateTimeService _dateTimeService;
+ private readonly IPictureViewModelService _pictureViewModelService;
+ private readonly SeoSettings _seoSettings;
+ #endregion
+
+ #region Blog posts
+
+ public IActionResult Index()
+ {
+ return RedirectToAction("List");
+ }
+
+ public IActionResult List()
+ {
+ return View();
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ [HttpPost]
+ public async Task<IActionResult> List(DataSourceRequest command)
+ {
+ var blogPosts = await _blogViewModelService.PrepareBlogPostsModel(command.Page, command.PageSize);
+ var gridModel = new DataSourceResult {
+ Data = blogPosts.blogPosts,
+ Total = blogPosts.totalCount
+ };
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public async Task<IActionResult> Create()
+ {
+ ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
+ var model = new BlogPostModel {
+ //default values
+ AllowComments = true,
+ CreateDate = DateTime.UtcNow
+ };
+
+ //locales
+ await AddLocales(_languageService, model.Locales);
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public async Task<IActionResult> Create(BlogPostModel model, bool continueEditing)
+ {
+ if (ModelState.IsValid)
+ {
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ var blogPost = await _blogViewModelService.InsertBlogPostModel(model);
+ Success(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Added"));
+ return continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List");
+ }
+
+ //If we got this far, something failed, redisplay form
+ ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ public async Task<IActionResult> Edit(string id)
+ {
+ var blogPost = await _blogService.GetBlogPostById(id);
+ if (blogPost == null)
+ //No blog post found with the specified id
+ return RedirectToAction("List");
+
+ if (!blogPost.LimitedToStores || (blogPost.LimitedToStores &&
+ blogPost.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ blogPost.Stores.Count > 1))
+ {
+ Warning(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Permissions"));
+ }
+ else
+ {
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction("List");
+ }
+
+ ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
+ var model = blogPost.ToModel(_dateTimeService);
+
+ //locales
+ await AddLocales(_languageService, model.Locales, (locale, languageId) =>
+ {
+ locale.Title = blogPost.GetTranslation(x => x.Title, languageId, false);
+ locale.Body = blogPost.GetTranslation(x => x.Body, languageId, false);
+ locale.BodyOverview = blogPost.GetTranslation(x => x.BodyOverview, languageId, false);
+ locale.MetaKeywords = blogPost.GetTranslation(x => x.MetaKeywords, languageId, false);
+ locale.MetaDescription = blogPost.GetTranslation(x => x.MetaDescription, languageId, false);
+ locale.MetaTitle = blogPost.GetTranslation(x => x.MetaTitle, languageId, false);
+ locale.SeName = blogPost.GetSeName(languageId, false);
+ });
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public async Task<IActionResult> Edit(BlogPostModel model, bool continueEditing)
+ {
+ var blogPost = await _blogService.GetBlogPostById(model.Id);
+ if (blogPost == null)
+ //No blog post found with the specified id
+ return RedirectToAction("List");
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction("Edit", new { id = blogPost.Id });
+
+ if (ModelState.IsValid)
+ {
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ blogPost = await _blogViewModelService.UpdateBlogPostModel(model, blogPost);
+ Success(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Updated"));
+
+ if (continueEditing)
+ {
+ //selected tab
+ await SaveSelectedTabIndex();
+ return RedirectToAction("Edit", new { id = blogPost.Id });
+ }
+ return RedirectToAction("List");
+ }
+
+ //If we got this far, something failed, redisplay form
+ ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ [HttpPost]
+ public async Task<IActionResult> Delete(string id)
+ {
+ var blogPost = await _blogService.GetBlogPostById(id);
+ if (blogPost == null)
+ //No blog post found with the specified id
+ return RedirectToAction("List");
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction("Edit", new { id = blogPost.Id });
+
+ if (ModelState.IsValid)
+ {
+ await _blogService.DeleteBlogPost(blogPost);
+ Success(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Deleted"));
+ return RedirectToAction("List");
+ }
+
+ Error(ModelState);
+ return RedirectToAction("Edit", new { id });
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ public async Task<IActionResult> Preview(string id)
+ {
+ var blogPost = await _blogService.GetBlogPostById(id);
+ if (blogPost == null)
+ return RedirectToAction("List");
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction("List");
+
+ var model = blogPost.ToModel(_dateTimeService);
+ return View(model);
+ }
+
+ #endregion
+
+ #region Picture
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ public async Task<IActionResult> PicturePopup(string blogpostId)
+ {
+ var blogpost = await _blogService.GetBlogPostById(blogpostId);
+ if (blogpost == null)
+ return Content("Blog post not exist");
+
+ if (!blogpost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Content(NoAccessToBlogPostMessage);
+
+ if (string.IsNullOrEmpty(blogpost.PictureId))
+ return Content("Picture not exist");
+
+ return View("Partials/PicturePopup",
+ await _pictureViewModelService.PreparePictureModel(blogpost.PictureId, blogpost.Id));
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ public async Task<IActionResult> PicturePopup(PictureModel model)
+ {
+ if (ModelState.IsValid)
+ {
+ var blogpost = await _blogService.GetBlogPostById(model.ObjectId);
+ if (blogpost == null)
+ throw new ArgumentException("No blog post found with the specified id");
+
+ if (!blogpost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Content(NoAccessToBlogPostMessage);
+
+ if (string.IsNullOrEmpty(blogpost.PictureId))
+ throw new ArgumentException("No picture found with the specified id");
+
+ if (blogpost.PictureId != model.Id)
+ throw new ArgumentException("Picture ident doesn't fit with blog post");
+
+ await _pictureViewModelService.UpdatePicture(model);
+
+ return Content("");
+ }
+
+ Error(ModelState);
+
+ return View("Partials/PicturePopup", model);
+ }
+
+ #endregion
+
+ #region Comments
+
+ public IActionResult Comments(string filterByBlogPostId)
+ {
+ ViewBag.FilterByBlogPostId = filterByBlogPostId;
+ return View();
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ [HttpPost]
+ public async Task<IActionResult> Comments(string filterByBlogPostId, DataSourceRequest command)
+ {
+ var model = await _blogViewModelService.PrepareBlogPostCommentsModel(filterByBlogPostId, command.Page,
+ command.PageSize);
+ var gridModel = new DataSourceResult {
+ Data = model.blogComments,
+ Total = model.totalCount
+ };
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ public async Task<IActionResult> CommentDelete(string id)
+ {
+ var comment = await _blogService.GetBlogCommentById(id);
+ if (comment == null)
+ throw new ArgumentException("No comment found with the specified id");
+
+ var blogPost = await _blogService.GetBlogPostById(comment.BlogPostId);
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return ErrorForKendoGridJson(NoAccessToBlogPostMessage);
+
+ if (ModelState.IsValid)
+ {
+ await _blogService.DeleteBlogComment(comment);
+ //update totals
+ var comments = await _blogService.GetBlogCommentsByBlogPostId(blogPost.Id);
+ blogPost.CommentCount = comments.Count;
+ await _blogService.UpdateBlogPost(blogPost);
+ return new JsonResult("");
+ }
+
+ return ErrorForKendoGridJson(ModelState);
+ }
+
+ #endregion
+
+ #region Products
+
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ [HttpPost]
+ public async Task<IActionResult> Products(string blogPostId, DataSourceRequest command)
+ {
+ var blogPost = await _blogService.GetBlogPostById(blogPostId);
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return ErrorForKendoGridJson(NoAccessToBlogPostMessage);
+
+ var model = await _blogViewModelService.PrepareBlogProductsModel(blogPostId, command.Page, command.PageSize);
+ var gridModel = new DataSourceResult {
+ Data = model.blogProducts,
+ Total = model.totalCount
+ };
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public async Task<IActionResult> ProductAddPopup(string blogPostId)
+ {
+ var blogPost = await _blogService.GetBlogPostById(blogPostId);
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return View(NoAccessToBlogPostMessage);
+
+ var model = await _blogViewModelService.PrepareBlogModelAddProductModel(blogPostId);
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ public async Task<IActionResult> ProductAddPopupList(DataSourceRequest command,
+ BlogProductModel.AddProductModel model)
+ {
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+
+ var products = await _blogViewModelService.PrepareProductModel(model, command.Page, command.PageSize);
+
+ var gridModel = new DataSourceResult {
+ Data = products.products.ToList(),
+ Total = products.totalCount
+ };
+
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ public async Task<IActionResult> ProductAddPopup(string blogPostId, BlogProductModel.AddProductModel model)
+ {
+ var blogPost = await _blogService.GetBlogPostById(blogPostId);
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return View(NoAccessToBlogPostMessage);
+
+ if (model.SelectedProductIds != null) await _blogViewModelService.InsertProductModel(blogPostId, model);
+ return Content("");
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public async Task<IActionResult> UpdateProduct(string blogPostId, BlogProductModel model)
+ {
+ var blogPost = await _blogService.GetBlogPostById(blogPostId);
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ ModelState.AddModelError("Blog", NoAccessToBlogPostMessage);
+
+ if (ModelState.IsValid)
+ {
+ await _blogViewModelService.UpdateProductModel(model);
+ return new JsonResult("");
+ }
+
+ return ErrorForKendoGridJson(ModelState);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ public async Task<IActionResult> DeleteProduct(string id)
+ {
+ var bp = await _blogService.GetBlogProductById(id) ?? throw new ArgumentException("No blog product found with the specified id");
+ var blogPost = await _blogService.GetBlogPostById(bp.BlogPostId);
+
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ ModelState.AddModelError("Blog", NoAccessToBlogPostMessage);
+
+ if (ModelState.IsValid)
+ {
+ await _blogViewModelService.DeleteProductModel(id);
+ return new JsonResult("");
+ }
+
+ return ErrorForKendoGridJson(ModelState);
+ }
+
+ #endregion
+
+ #region Categories
+
+ public IActionResult CategoryList()
+ {
+ return View();
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ [HttpPost]
+ public async Task<IActionResult> CategoryList(DataSourceRequest command)
+ {
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var categories = await _blogService.GetAllBlogCategories(storeId);
+ var gridModel = new DataSourceResult {
+ Data = categories,
+ Total = categories.Count
+ };
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public async Task<IActionResult> CategoryCreate()
+ {
+ ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
+ var model = new BlogCategoryModel();
+ //locales
+ await AddLocales(_languageService, model.Locales);
+
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public async Task<IActionResult> CategoryCreate(BlogCategoryModel model, bool continueEditing)
+ {
+ if (ModelState.IsValid)
+ {
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ var blogCategory = model.ToEntity();
+ blogCategory.SeName = SeoExtensions.GetSeName(
+ string.IsNullOrEmpty(blogCategory.SeName) ? blogCategory.Name : blogCategory.SeName,
+ _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls,
+ _seoSettings.SeoCharConversion);
+
+ await _blogService.InsertBlogCategory(blogCategory);
+ Success(_translationService.GetResource("Admin.Content.Blog.BlogCategory.Added"));
+ return continueEditing
+ ? RedirectToAction("CategoryEdit", new { id = blogCategory.Id })
+ : RedirectToAction(CategoryListAction);
+ }
+
+ //If we got this far, something failed, redisplay form
+ ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
+ //locales
+ await AddLocales(_languageService, model.Locales);
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ public async Task<IActionResult> CategoryEdit(string id)
+ {
+ var blogCategory = await _blogService.GetBlogCategoryById(id);
+ if (blogCategory == null)
+ //No blog post found with the specified id
+ return RedirectToAction(CategoryListAction);
+
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction(CategoryListAction);
+
+ ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
+ var model = blogCategory.ToModel();
+ //locales
+ await AddLocales(_languageService, model.Locales, (locale, languageId) =>
+ {
+ locale.Name = blogCategory.GetTranslation(x => x.Name, languageId, false);
+ });
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public async Task<IActionResult> CategoryEdit(BlogCategoryModel model, bool continueEditing)
+ {
+ var blogCategory = await _blogService.GetBlogCategoryById(model.Id);
+ if (blogCategory == null)
+ //No blog post found with the specified id
+ return RedirectToAction(CategoryListAction);
+
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction(CategoryListAction);
+
+ if (ModelState.IsValid)
+ {
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ blogCategory = model.ToEntity(blogCategory);
+ blogCategory.SeName = SeoExtensions.GetSeName(
+ string.IsNullOrEmpty(blogCategory.SeName) ? blogCategory.Name : blogCategory.SeName,
+ _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls,
+ _seoSettings.SeoCharConversion);
+ await _blogService.UpdateBlogCategory(blogCategory);
+ Success(_translationService.GetResource("Admin.Content.Blog.BlogCategory.Updated"));
+ if (continueEditing)
+ {
+ //selected tab
+ await SaveSelectedTabIndex();
+
+ return RedirectToAction("CategoryEdit", new { id = blogCategory.Id });
+ }
+
+ return RedirectToAction(CategoryListAction);
+ }
+
+ //If we got this far, something failed, redisplay form
+ ViewBag.AllLanguages = await _languageService.GetAllLanguages(true);
+
+ //locales
+ await AddLocales(_languageService, model.Locales, (locale, languageId) =>
+ {
+ locale.Name = blogCategory.GetTranslation(x => x.Name, languageId, false);
+ });
+
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ [HttpPost]
+ public async Task<IActionResult> CategoryDelete(string id)
+ {
+ var blogCategory = await _blogService.GetBlogCategoryById(id);
+ if (blogCategory == null)
+ //No blog post found with the specified id
+ return RedirectToAction(CategoryListAction);
+
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction(CategoryListAction);
+
+ if (ModelState.IsValid)
+ {
+ await _blogService.DeleteBlogCategory(blogCategory);
+
+ Success(_translationService.GetResource("Admin.Content.Blog.BlogCategory.Deleted"));
+ return RedirectToAction(CategoryListAction);
+ }
+
+ Error(ModelState);
+ return RedirectToAction("CategoryEdit", new { id = blogCategory.Id });
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ [HttpPost]
+ public async Task<IActionResult> CategoryPostList(string categoryId)
+ {
+ var blogCategory = await _blogService.GetBlogCategoryById(categoryId);
+ if (blogCategory == null)
+ return ErrorForKendoGridJson("blogCategory no exists");
+
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return ErrorForKendoGridJson(NoAccessToBlogCategoryMessage);
+
+ var blogposts = new List<AdminShared.Models.Blogs.BlogCategoryPost>();
+ foreach (var item in blogCategory.BlogPosts)
+ {
+ var post = new AdminShared.Models.Blogs.BlogCategoryPost {
+ Id = item.Id,
+ BlogPostId = item.BlogPostId
+ };
+ var _post = await _blogService.GetBlogPostById(item.BlogPostId);
+ if (_post != null)
+ post.Name = _post.Title;
+
+ blogposts.Add(post);
+ }
+
+ var gridModel = new DataSourceResult {
+ Data = blogposts,
+ Total = blogCategory.BlogPosts.Count
+ };
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ public async Task<IActionResult> CategoryPostDelete(string categoryId, string id)
+ {
+ var blogCategory = await _blogService.GetBlogCategoryById(categoryId);
+ if (blogCategory == null)
+ return ErrorForKendoGridJson("blogCategory no exists");
+
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return ErrorForKendoGridJson(NoAccessToBlogCategoryMessage);
+
+ if (ModelState.IsValid)
+ {
+ var post = blogCategory.BlogPosts.FirstOrDefault(x => x.Id == id);
+ if (post != null)
+ {
+ blogCategory.BlogPosts.Remove(post);
+ await _blogService.UpdateBlogCategory(blogCategory);
+ }
+
+ return new JsonResult("");
+ }
+
+ return ErrorForKendoGridJson(ModelState);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public IActionResult BlogPostAddPopup(string categoryId)
+ {
+ var model = new AddBlogPostCategoryModel {
+ CategoryId = categoryId
+ };
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ public async Task<IActionResult> BlogPostAddPopup(AddBlogPostCategoryModel model)
+ {
+ if (model.SelectedBlogPostIds == null)
+ {
+ return Content("");
+ }
+
+ var blogCategory = await _blogService.GetBlogCategoryById(model.CategoryId);
+ if (blogCategory == null)
+ {
+ return Content("");
+ }
+
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ {
+ return Content(NoAccessToBlogCategoryMessage);
+ }
+
+ await AddSelectedPostsToBlogCategory(blogCategory, model.SelectedBlogPostIds);
+
+ return Content("");
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ public async Task<IActionResult> BlogPostAddPopupList(DataSourceRequest command, AddBlogPostCategoryModel model)
+ {
+ var gridModel = new DataSourceResult();
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+
+ var posts = await _blogService.GetAllBlogPosts(model.SearchStoreId, blogPostName: model.SearchBlogTitle,
+ pageIndex: command.Page - 1, pageSize: command.PageSize);
+ gridModel.Data = posts.Select(x => new { x.Id, Name = x.Title });
+ gridModel.Total = posts.TotalCount;
+
+ return Json(gridModel);
+ }
+
+ private async Task AddSelectedPostsToBlogCategory(BlogCategory blogCategory, string[] postIds)
+ {
+ foreach (var id in postIds)
+ {
+ await AddPostToBlogCategoryIfValid(blogCategory, id);
+ }
+ }
+
+ private async Task AddPostToBlogCategoryIfValid(BlogCategory blogCategory, string postId)
+ {
+ var post = await _blogService.GetBlogPostById(postId);
+ if (post == null)
+ {
+ return;
+ }
+
+ if (!post.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ {
+ // Skip posts that the user doesn't have access to
+ return;
+ }
+
+ if (blogCategory.BlogPosts.Any(x => x.BlogPostId == postId))
+ {
+ // Skip if the post is already in the category
+ return;
+ }
+
+ blogCategory.BlogPosts.Add(new Domain.Blogs.BlogCategoryPost { BlogPostId = postId });
+ await _blogService.UpdateBlogCategory(blogCategory);
+ }
+
+ #endregion
+}
\ No newline at end of file