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
feat(arch001): add Picture region to BaseCategoryController
KrzysztofPajakae15cfadd36d
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseCategoryControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseCategoryControllerTests.csindex be441a748..22d6d6c45 100644--- a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseCategoryControllerTests.cs+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseCategoryControllerTests.cs@@ -225,4 +225,34 @@ public class BaseCategoryControllerTests_categoryViewModelServiceMock.Verify(v => v.InsertCategoryModel(It.IsAny<CategoryModel>()), Times.Once);}++ // --- PicturePopup --------------------------------------------------------------------------------++ [TestMethod]+ public async Task PicturePopupGet_ScopeDeniesAccess_ReturnsDeniedContent()+ {+ var category = new Category { Id = "c1", PictureId = "pic-1" };+ _categoryServiceMock.Setup(c => c.GetCategoryById("c1")).ReturnsAsync(category);+ _scopeMock.Setup(s => s.HasAccess(category)).ReturnsAsync(false);++ var result = await _controller.PicturePopup("c1");++ var content = result as ContentResult;+ Assert.IsNotNull(content);+ Assert.AreEqual("This is not your category", content.Content);+ }++ [TestMethod]+ public async Task PicturePopupGet_CategoryHasNoPicture_ReturnsNotExistContent()+ {+ var category = new Category { Id = "c1", PictureId = null };+ _categoryServiceMock.Setup(c => c.GetCategoryById("c1")).ReturnsAsync(category);+ _scopeMock.Setup(s => s.HasAccess(category)).ReturnsAsync(true);++ var result = await _controller.PicturePopup("c1");++ var content = result as ContentResult;+ Assert.IsNotNull(content);+ Assert.AreEqual("Picture not exist", content.Content);+ }}diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseCategoryController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseCategoryController.csindex b0c07cd03..8a99f5a9c 100644--- a/src/Web/Grand.Web.AdminShared/Controllers/BaseCategoryController.cs+++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseCategoryController.cs@@ -7,6 +7,7 @@ using Grand.Domain.Permissions;using Grand.Web.AdminShared.Extensions.Mapping;using Grand.Web.AdminShared.Interfaces;using Grand.Web.AdminShared.Models.Catalog;+using Grand.Web.AdminShared.Models.Common;using Grand.Web.Common.Controllers;using Grand.Web.Common.DataSource;using Grand.Web.Common.Filters;@@ -167,4 +168,43 @@ public abstract class BaseCategoryController(}#endregion++ #region Picture++ [PermissionAuthorizeAction(PermissionActionName.Preview)]+ public async Task<IActionResult> PicturePopup(string categoryId)+ {+ var category = await categoryService.GetCategoryById(categoryId);+ if (category == null) return Content("Category not exist");+ if (!await scope.HasAccess(category)) return Content("This is not your category");+ if (string.IsNullOrEmpty(category.PictureId)) return Content("Picture not exist");++ return View("Partials/PicturePopup",+ await pictureViewModelService.PreparePictureModel(category.PictureId, category.Id));+ }++ [PermissionAuthorizeAction(PermissionActionName.Edit)]+ [HttpPost]+ public async Task<IActionResult> PicturePopup(PictureModel model)+ {+ if (ModelState.IsValid)+ {+ var category = await categoryService.GetCategoryById(model.ObjectId);+ if (category == null)+ throw new ArgumentException("No category found with the specified id");+ if (!await scope.HasAccess(category)) return Content("This is not your category");+ if (string.IsNullOrEmpty(category.PictureId))+ throw new ArgumentException("No picture found with the specified id");+ if (category.PictureId != model.Id)+ throw new ArgumentException("Picture ident doesn't fit with category");++ await pictureViewModelService.UpdatePicture(model);+ return Content("");+ }++ Error(ModelState);+ return View("Partials/PicturePopup", model);+ }++ #endregion}