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.

Refactoring - Localizable picture attributes

KrzysztofPajakc951ec7fbe29
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Category/PicturePopup.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Category/PicturePopup.cshtml
deleted file mode 100644
index 00bf61994..000000000
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Category/PicturePopup.cshtml
+++ /dev/null
@@ -1,87 +0,0 @@
-@using Microsoft.AspNetCore.Mvc.Razor;
-
-@model CategoryModel.PictureModel
-@{
- Layout = Grand.Web.Admin.Extensions.Constants.Layout_AdminPopup;
- //page title
- ViewBag.Title = Loc["Admin.Catalog.Categories.Picture"];
-}
-<form asp-area="@Constants.AreaAdmin" asp-controller="Category" asp-action="PicturePopup" enctype="multipart/form-data" method="post"
- asp-route-CategoryId="@Context.Request.Query["CategoryId"]">
-
-
- <!-- #region languages template -->
- @{ Func<int, HelperResult> template = @<div class="form-body">
- <div class="form-group">
- <admin-label asp-for="@Model.Locales[item].AltAttribute" class="col-sm-3 control-label" />
- <div class="col-md-9 col-sm-9">
- <admin-input asp-for="@Model.Locales[item].AltAttribute" />
- <span asp-validation-for="@Model.Locales[item].AltAttribute"></span>
- </div>
- </div>
- <div class="form-group">
- <admin-label asp-for="@Model.Locales[item].TitleAttribute" class="col-sm-3 control-label" />
- <div class="col-md-9 col-sm-9">
- <admin-input asp-for="@Model.Locales[item].TitleAttribute" />
- <span asp-validation-for="@Model.Locales[item].TitleAttribute"></span>
- </div>
- </div>
- <input asp-for="@Model.Locales[item].LanguageId" type="hidden" />
- </div>;
- }
-
- <div asp-validation-summary="All"></div>
- <input asp-for="CategoryId" type="hidden" />
- <input asp-for="Id" type="hidden" />
- <input asp-for="PictureUrl" type="hidden" />
- <div class="row">
- <div class="col-md-12">
- <div class="x_panel light form-fit">
- <div class="x_content form">
- <div class="form-horizontal">
- <div class="form-body">
- <div class="form-group">
- <admin-label asp-for="PictureUrl" />
- <div class="col-md-9 col-sm-9">
- <a href="@Model.PictureUrl" target="_blank"><img src="@Model.PictureUrl" width="150" /></a>
- </div>
- </div>
- <localized-editor localized-template=template name="picturevalue-localized" [email protected](c=>c.LanguageId).ToList()>
- <div class="form-body">
- <div class="form-group">
- <admin-label asp-for="AltAttribute" class="col-sm-3 control-label" />
- <div class="col-md-9 col-sm-9">
- <admin-input asp-for="AltAttribute" />
- <span asp-validation-for="AltAttribute"></span>
- </div>
- </div>
- <div class="form-group">
- <admin-label asp-for="TitleAttribute" class="col-sm-3 control-label" />
- <div class="col-md-9 col-sm-9">
- <admin-input asp-for="TitleAttribute" />
- <span asp-validation-for="TitleAttribute"></span>
- </div>
- </div>
- </div>
- </localized-editor>
- <div class="form-actions">
- <div class="row">
- <div class="offset-md-3 offset-sm-3 col-md-9 col-sm-9">
- <button class="k-button" type="submit" name="save"><i class="fa fa-check"></i>@Loc["Admin.Common.Save"] </button>
- </div>
- </div>
- </div>
-
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- @if (ViewBag.RefreshPage == true)
- {
- <script>
- window.close();
- </script>
- }
-</form>
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Brand/PicturePopup.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/PicturePopup.cshtml
similarity index 92%
rename from src/Web/Grand.Web.Admin/Areas/Admin/Views/Brand/PicturePopup.cshtml
rename to src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/PicturePopup.cshtml
index b179291ce..1e0b0d68f 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Brand/PicturePopup.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/PicturePopup.cshtml
@@ -1,15 +1,12 @@
@using Microsoft.AspNetCore.Mvc.Razor;
-@model BrandModel.PictureModel
+@model PictureModel
@{
Layout = Grand.Web.Admin.Extensions.Constants.Layout_AdminPopup;
//page title
- ViewBag.Title = Loc["Admin.Catalog.Brands.Picture"];
+ ViewBag.Title = Loc["Admin.Catalog.Picture"];
}
-<form asp-area="@Constants.AreaAdmin" asp-controller="Brand" asp-action="PicturePopup" enctype="multipart/form-data" method="post"
- asp-route-BrandId="@Context.Request.Query["BrandId"]">
-
-
+<form asp-area="@Constants.AreaAdmin" asp-action="PicturePopup" enctype="multipart/form-data" method="post">
<!-- #region languages template -->
@{ Func<int, HelperResult> template = @<div class="form-body">
<div class="form-group">
@@ -29,10 +26,9 @@
<input asp-for="@Model.Locales[item].LanguageId" type="hidden" />
</div>;
}
-
<div asp-validation-summary="All"></div>
- <input asp-for="BrandId" type="hidden" />
<input asp-for="Id" type="hidden" />
+ <input asp-for="ObjectId" type="hidden" />
<input asp-for="PictureUrl" type="hidden" />
<div class="row">
<div class="col-md-12">
diff --git a/src/Web/Grand.Web.Admin/Controllers/BrandController.cs b/src/Web/Grand.Web.Admin/Controllers/BrandController.cs
index 140db0ef3..c507d1a8c 100644
--- a/src/Web/Grand.Web.Admin/Controllers/BrandController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/BrandController.cs
@@ -10,6 +10,7 @@ using Grand.Infrastructure;
using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Catalog;
+using Grand.Web.Admin.Models.Common;
using Grand.Web.Common.DataSource;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Security.Authorization;
@@ -35,6 +36,7 @@ namespace Grand.Web.Admin.Controllers
private readonly IGroupService _groupService;
private readonly IExportManager _exportManager;
private readonly IImportManager _importManager;
+ private readonly IPictureViewModelService _pictureViewModelService;
#endregion
#region Constructors
@@ -48,7 +50,8 @@ namespace Grand.Web.Admin.Controllers
ITranslationService translationService,
IGroupService groupService,
IExportManager exportManager,
- IImportManager importManager)
+ IImportManager importManager,
+ IPictureViewModelService pictureViewModelService)
{
_brandViewModelService = brandViewModelService;
_brandService = brandService;
@@ -59,6 +62,7 @@ namespace Grand.Web.Admin.Controllers
_groupService = groupService;
_exportManager = exportManager;
_importManager = importManager;
+ _pictureViewModelService = pictureViewModelService;
}
#endregion
@@ -106,8 +110,7 @@ namespace Grand.Web.Admin.Controllers
}
var brands = await _brandService.GetAllBrands(model.SearchBrandName,
model.SearchStoreId, command.Page - 1, command.PageSize, true);
- var gridModel = new DataSourceResult
- {
+ var gridModel = new DataSourceResult {
Data = brands.Select(x => x.ToModel()),
Total = brands.TotalCount
};
@@ -297,39 +300,38 @@ namespace Grand.Web.Admin.Controllers
if (!permission.allow)
return Content(permission.message);
- var (model, picture) = await _brandViewModelService.PreparePictureModel(brand);
- //locales
- await AddLocales(_languageService, model.Locales, (locale, languageId) =>
- {
- locale.AltAttribute = picture?.GetTranslation(x => x.AltAttribute, languageId, false);
- locale.TitleAttribute = picture?.GetTranslation(x => x.TitleAttribute, languageId, false);
- });
-
- return View(model);
+ return View("PicturePopup", await _pictureViewModelService.PreparePictureModel(brand.PictureId, brand.Id));
}
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> PicturePopup(BrandModel.PictureModel model)
+ public async Task<IActionResult> PicturePopup(PictureModel model)
{
if (ModelState.IsValid)
{
- var brand = await _brandService.GetBrandById(model.BrandId);
+ var brand = await _brandService.GetBrandById(model.ObjectId);
if (brand == null)
throw new ArgumentException("No brand found with the specified id");
+ var permission = await CheckAccessToBrand(brand);
+ if (!permission.allow)
+ return Content(permission.message);
+
if (string.IsNullOrEmpty(brand.PictureId))
throw new ArgumentException("No picture found with the specified id");
- await _brandViewModelService.UpdateBrandPicture(model);
+ if (brand.PictureId != model.Id)
+ throw new ArgumentException("Picture ident doesn't fit with brand");
+
+ await _pictureViewModelService.UpdatePicture(model);
ViewBag.RefreshPage = true;
- return View(model);
+ return View("PicturePopup", model);
}
Error(ModelState);
- return View(model);
+ return View("PicturePopup", model);
}
#endregion
@@ -393,8 +395,7 @@ namespace Grand.Web.Admin.Controllers
return ErrorForKendoGridJson(permission.message);
var (activityLogModels, totalCount) = await _brandViewModelService.PrepareActivityLogModel(brandId, command.Page, command.PageSize);
- var gridModel = new DataSourceResult
- {
+ var gridModel = new DataSourceResult {
Data = activityLogModels.ToList(),
Total = totalCount
};
diff --git a/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs b/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
index 1070d7119..6703029fb 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
@@ -11,6 +11,7 @@ using Grand.Infrastructure;
using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Catalog;
+using Grand.Web.Admin.Models.Common;
using Grand.Web.Common.DataSource;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Security.Authorization;
@@ -37,7 +38,7 @@ namespace Grand.Web.Admin.Controllers
private readonly IWorkContext _workContext;
private readonly IGroupService _groupService;
private readonly IImportManager _importManager;
-
+ private readonly IPictureViewModelService _pictureViewModelService;
#endregion
#region Constructors
@@ -52,7 +53,8 @@ namespace Grand.Web.Admin.Controllers
IExportManager exportManager,
IWorkContext workContext,
IGroupService groupService,
- IImportManager importManager)
+ IImportManager importManager,
+ IPictureViewModelService pictureViewModelService)
{
_categoryService = categoryService;
_categoryViewModelService = categoryViewModelService;
@@ -64,6 +66,7 @@ namespace Grand.Web.Admin.Controllers
_workContext = workContext;
_groupService = groupService;
_importManager = importManager;
+ _pictureViewModelService = pictureViewModelService;
}
#endregion
@@ -270,40 +273,34 @@ namespace Grand.Web.Admin.Controllers
if (!permission.allow)
return Content(permission.message);
-
- var (model, picture) = await _categoryViewModelService.PreparePictureModel(category);
- //locales
- await AddLocales(_languageService, model.Locales, (locale, languageId) =>
- {
- locale.AltAttribute = picture?.GetTranslation(x => x.AltAttribute, languageId, false);
- locale.TitleAttribute = picture?.GetTranslation(x => x.TitleAttribute, languageId, false);
- });
-
- return View(model);
+ return View("PicturePopup", await _pictureViewModelService.PreparePictureModel(category.PictureId, category.Id));
}
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> PicturePopup(CategoryModel.PictureModel model)
+ public async Task<IActionResult> PicturePopup(PictureModel model)
{
if (ModelState.IsValid)
{
- var category = await _categoryService.GetCategoryById(model.CategoryId);
+ var category = await _categoryService.GetCategoryById(model.ObjectId);
if (category == null)
throw new ArgumentException("No category found with the specified id");
if (string.IsNullOrEmpty(category.PictureId))
throw new ArgumentException("No picture found with the specified id");
- await _categoryViewModelService.UpdateCategoryPicture(model);
+ if (category.PictureId != model.Id)
+ throw new ArgumentException("Picture ident doesn't fit with category");
+
+ await _pictureViewModelService.UpdatePicture(model);
ViewBag.RefreshPage = true;
- return View(model);
+ return View("PicturePopup", model);
}
Error(ModelState);
- return View(model);
+ return View("PicturePopup", model);
}
#endregion
diff --git a/src/Web/Grand.Web.Admin/Interfaces/IBrandViewModelService.cs b/src/Web/Grand.Web.Admin/Interfaces/IBrandViewModelService.cs
index f7781aae2..ebeebdda0 100644
--- a/src/Web/Grand.Web.Admin/Interfaces/IBrandViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Interfaces/IBrandViewModelService.cs
@@ -14,8 +14,6 @@ namespace Grand.Web.Admin.Interfaces
Task<Brand> InsertBrandModel(BrandModel model);
Task<Brand> UpdateBrandModel(Brand brand, BrandModel model);
Task DeleteBrand(Brand brand);
- Task<(BrandModel.PictureModel model, Picture Picture)> PreparePictureModel(Brand brand);
- Task UpdateBrandPicture(BrandModel.PictureModel model);
Task<(IEnumerable<BrandModel.ActivityLogModel> activityLogModels, int totalCount)> PrepareActivityLogModel(string brandId, int pageIndex, int pageSize);
}
}
diff --git a/src/Web/Grand.Web.Admin/Interfaces/ICategoryViewModelService.cs b/src/Web/Grand.Web.Admin/Interfaces/ICategoryViewModelService.cs
index 8508bf2ae..e7de7f490 100644
--- a/src/Web/Grand.Web.Admin/Interfaces/ICategoryViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Interfaces/ICategoryViewModelService.cs
@@ -1,5 +1,4 @@
using Grand.Domain.Catalog;
-using Grand.Domain.Media;
using Grand.Web.Admin.Models.Catalog;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -15,8 +14,6 @@ namespace Grand.Web.Admin.Interfaces
Task<Category> InsertCategoryModel(CategoryModel model);
Task<Category> UpdateCategoryModel(Category category, CategoryModel model);
Task DeleteCategory(Category category);
- Task<(CategoryModel.PictureModel model, Picture Picture)> PreparePictureModel(Category category);
- Task UpdateCategoryPicture(CategoryModel.PictureModel model);
Task<(IEnumerable<CategoryModel.CategoryProductModel> categoryProductModels, int totalCount)> PrepareCategoryProductModel(string categoryId, int pageIndex, int pageSize);
Task<ProductCategory> UpdateProductCategoryModel(CategoryModel.CategoryProductModel model);
Task DeleteProductCategoryModel(string id, string productId);
diff --git a/src/Web/Grand.Web.Admin/Interfaces/IPictureViewModelService.cs b/src/Web/Grand.Web.Admin/Interfaces/IPictureViewModelService.cs
new file mode 100644
index 000000000..ad5ff6c8a
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Interfaces/IPictureViewModelService.cs
@@ -0,0 +1,11 @@
+using Grand.Web.Admin.Models.Common;
+using System.Threading.Tasks;
+
+namespace Grand.Web.Admin.Interfaces
+{
+ public interface IPictureViewModelService
+ {
+ Task<PictureModel> PreparePictureModel(string pictureId, string objectId);
+ Task UpdatePicture(PictureModel model);
+ }
+}
diff --git a/src/Web/Grand.Web.Admin/Models/Catalog/BrandModel.cs b/src/Web/Grand.Web.Admin/Models/Catalog/BrandModel.cs
index 7230a6356..67fd3b5af 100644
--- a/src/Web/Grand.Web.Admin/Models/Catalog/BrandModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Catalog/BrandModel.cs
@@ -115,41 +115,7 @@ namespace Grand.Web.Admin.Models.Catalog
public string CustomerEmail { get; set; }
}
- public partial class PictureModel : BaseEntityModel, ILocalizedModel<PictureModel.PictureLocalizedModel>
- {
- public PictureModel()
- {
- Locales = new List<PictureLocalizedModel>();
- }
-
- public string BrandId { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Brands.Picture")]
- public string PictureUrl { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Brands.Picture.Fields.AltAttribute")]
- public string AltAttribute { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Brands.Picture.Fields.TitleAttribute")]
- public string TitleAttribute { get; set; }
-
- public IList<PictureLocalizedModel> Locales { get; set; }
-
- public partial class PictureLocalizedModel : ILocalizedModelLocal
- {
- public string LanguageId { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Brands.Picture.Fields.AltAttribute")]
- public string AltAttribute { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Brands.Picture.Fields.TitleAttribute")]
- public string TitleAttribute { get; set; }
- }
- }
-
#endregion
-
-
}
public partial class BrandLocalizedModel : ILocalizedModelLocal, ISlugModelLocal
diff --git a/src/Web/Grand.Web.Admin/Models/Catalog/CategoryModel.cs b/src/Web/Grand.Web.Admin/Models/Catalog/CategoryModel.cs
index 68491ffac..9aaa4de4b 100644
--- a/src/Web/Grand.Web.Admin/Models/Catalog/CategoryModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Catalog/CategoryModel.cs
@@ -192,38 +192,6 @@ namespace Grand.Web.Admin.Models.Catalog
public string CustomerEmail { get; set; }
}
- public partial class PictureModel : BaseEntityModel, ILocalizedModel<PictureModel.PictureLocalizedModel>
- {
- public PictureModel()
- {
- Locales = new List<PictureLocalizedModel>();
- }
-
- public string CategoryId { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Categories.Picture")]
- public string PictureUrl { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Categories.Picture.Fields.AltAttribute")]
- public string AltAttribute { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Categories.Picture.Fields.TitleAttribute")]
- public string TitleAttribute { get; set; }
-
- public IList<PictureLocalizedModel> Locales { get; set; }
-
- public partial class PictureLocalizedModel : ILocalizedModelLocal
- {
- public string LanguageId { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Categories.Picture.Fields.AltAttribute")]
- public string AltAttribute { get; set; }
-
- [GrandResourceDisplayName("Admin.Catalog.Categories.Picture.Fields.TitleAttribute")]
- public string TitleAttribute { get; set; }
- }
- }
-
#endregion
}
diff --git a/src/Web/Grand.Web.Admin/Models/Common/PictureModel.cs b/src/Web/Grand.Web.Admin/Models/Common/PictureModel.cs
new file mode 100644
index 000000000..5d2236261
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Models/Common/PictureModel.cs
@@ -0,0 +1,38 @@
+using Grand.Infrastructure.ModelBinding;
+using Grand.Infrastructure.Models;
+using Grand.Web.Common.Models;
+using System.Collections.Generic;
+
+namespace Grand.Web.Admin.Models.Common
+{
+ public partial class PictureModel : BaseEntityModel, ILocalizedModel<PictureModel.PictureLocalizedModel>
+ {
+ public PictureModel()
+ {
+ Locales = new List<PictureLocalizedModel>();
+ }
+ public string ObjectId { get; set; }
+
+ [GrandResourceDisplayName("Admin.Catalog.Picture")]
+ public string PictureUrl { get; set; }
+
+ [GrandResourceDisplayName("Admin.Catalog.Picture.Fields.AltAttribute")]
+ public string AltAttribute { get; set; }
+
+ [GrandResourceDisplayName("Admin.Catalog.Picture.Fields.TitleAttribute")]
+ public string TitleAttribute { get; set; }
+
+ public IList<PictureLocalizedModel> Locales { get; set; }
+
+ public partial class PictureLocalizedModel : ILocalizedModelLocal
+ {
+ public string LanguageId { get; set; }
+
+ [GrandResourceDisplayName("Admin.Catalog.Picture.Fields.AltAttribute")]
+ public string AltAttribute { get; set; }
+
+ [GrandResourceDisplayName("Admin.Catalog.Picture.Fields.TitleAttribute")]
+ public string TitleAttribute { get; set; }
+ }
+ }
+}
diff --git a/src/Web/Grand.Web.Admin/Services/BrandViewModelService.cs b/src/Web/Grand.Web.Admin/Services/BrandViewModelService.cs
index a69dfdd44..0e8150a9e 100644
--- a/src/Web/Grand.Web.Admin/Services/BrandViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/BrandViewModelService.cs
@@ -9,7 +9,6 @@ using Grand.Business.Customers.Interfaces;
using Grand.Business.Storage.Interfaces;
using Grand.Domain.Catalog;
using Grand.Domain.Discounts;
-using Grand.Domain.Media;
using Grand.Domain.Seo;
using Grand.Infrastructure;
using Grand.Web.Admin.Extensions;
@@ -92,8 +91,7 @@ namespace Grand.Web.Admin.Services
var layouts = await _brandLayoutService.GetAllBrandLayouts();
foreach (var layout in layouts)
{
- model.AvailableBrandLayouts.Add(new SelectListItem
- {
+ model.AvailableBrandLayouts.Add(new SelectListItem {
Text = layout.Name,
Value = layout.Id
});
@@ -198,29 +196,6 @@ namespace Grand.Web.Admin.Services
//activity log
await _customerActivityService.InsertActivity("DeleteBrand", brand.Id, _translationService.GetResource("ActivityLog.DeleteBrand"), brand.Name);
}
- public virtual async Task<(BrandModel.PictureModel model, Picture Picture)> PreparePictureModel(Brand brand)
- {
- var picture = await _pictureService.GetPictureById(brand.PictureId);
- var model = new BrandModel.PictureModel {
- Id = picture.Id,
- BrandId = brand.Id,
- PictureUrl = picture != null ? await _pictureService.GetPictureUrl(picture) : null,
- AltAttribute = picture?.AltAttribute,
- TitleAttribute = picture?.TitleAttribute,
- };
- return (model, picture);
- }
- public virtual async Task UpdateBrandPicture(BrandModel.PictureModel model)
- {
- var picture = await _pictureService.GetPictureById(model.Id);
- if (picture == null)
- throw new ArgumentException("No picture found with the specified id");
-
- //Update picture fields
- await _pictureService.UpdatField(picture, x => x.AltAttribute, model.AltAttribute);
- await _pictureService.UpdatField(picture, x => x.TitleAttribute, model.TitleAttribute);
- await _pictureService.UpdatField(picture, x => x.Locales, model.Locales.ToTranslationProperty());
- }
public virtual async Task<(IEnumerable<BrandModel.ActivityLogModel> activityLogModels, int totalCount)> PrepareActivityLogModel(string brandId, int pageIndex, int pageSize)
{
@@ -229,8 +204,7 @@ namespace Grand.Web.Admin.Services
foreach (var x in activityLog)
{
var customer = await _customerService.GetCustomerById(x.CustomerId);
- var m = new BrandModel.ActivityLogModel
- {
+ var m = new BrandModel.ActivityLogModel {
Id = x.Id,
ActivityLogTypeName = (await _customerActivityService.GetActivityTypeById(x.ActivityLogTypeId))?.Name,
Comment = x.Comment,
diff --git a/src/Web/Grand.Web.Admin/Services/CategoryViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CategoryViewModelService.cs
index 7a71492fd..e7eec4162 100644
--- a/src/Web/Grand.Web.Admin/Services/CategoryViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CategoryViewModelService.cs
@@ -1,6 +1,5 @@
using Grand.Business.Catalog.Interfaces.Categories;
using Grand.Business.Catalog.Interfaces.Discounts;
-using Grand.Business.Catalog.Interfaces.Collections;
using Grand.Business.Catalog.Interfaces.Products;
using Grand.Business.Common.Extensions;
using Grand.Business.Common.Interfaces.Directory;
@@ -13,16 +12,15 @@ using Grand.Business.Storage.Interfaces;
using Grand.Domain.Catalog;
using Grand.Domain.Discounts;
using Grand.Domain.Seo;
-using Grand.Web.Common.Extensions;
using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Catalog;
+using Grand.Web.Common.Extensions;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using Grand.Domain.Media;
namespace Grand.Web.Admin.Services
{
@@ -47,7 +45,7 @@ namespace Grand.Web.Admin.Services
public CategoryViewModelService(ICategoryService categoryService, IProductCategoryService productCategoryService, ICategoryLayoutService categoryLayoutService, IDiscountService discountService,
ITranslationService translationService, IStoreService storeService, ICustomerService customerService, IPictureService pictureService,
- ISlugService slugService, ICustomerActivityService customerActivityService, IProductService productService,
+ ISlugService slugService, ICustomerActivityService customerActivityService, IProductService productService,
IVendorService vendorService, IDateTimeService dateTimeService, ILanguageService languageService, CatalogSettings catalogSettings, SeoSettings seoSettings)
{
_categoryService = categoryService;
@@ -76,8 +74,7 @@ namespace Grand.Web.Admin.Services
var layouts = await _categoryLayoutService.GetAllCategoryLayouts();
foreach (var layout in layouts)
{
- model.AvailableCategoryLayouts.Add(new SelectListItem
- {
+ model.AvailableCategoryLayouts.Add(new SelectListItem {
Text = layout.Name,
Value = layout.Id
});
@@ -120,10 +117,10 @@ namespace Grand.Web.Admin.Services
public virtual async Task<(IEnumerable<CategoryModel> categoryListModel, int totalCount)> PrepareCategoryListModel(CategoryListModel model, int pageIndex, int pageSize)
{
var categories = await _categoryService.GetAllCategories(
- categoryName: model.SearchCategoryName,
+ categoryName: model.SearchCategoryName,
storeId: model.SearchStoreId,
pageSize: pageSize,
- pageIndex: pageIndex - 1,
+ pageIndex: pageIndex - 1,
showHidden: true);
var categoryListModel = new List<CategoryModel>();
@@ -248,30 +245,6 @@ namespace Grand.Web.Admin.Services
await _customerActivityService.InsertActivity("DeleteCategory", category.Id, _translationService.GetResource("ActivityLog.DeleteCategory"), category.Name);
}
- public virtual async Task<(CategoryModel.PictureModel model, Picture Picture)> PreparePictureModel(Category category)
- {
- var picture = await _pictureService.GetPictureById(category.PictureId);
- var model = new CategoryModel.PictureModel {
- Id = picture.Id,
- CategoryId = category.Id,
- PictureUrl = picture != null ? await _pictureService.GetPictureUrl(picture) : null,
- AltAttribute = picture?.AltAttribute,
- TitleAttribute = picture?.TitleAttribute,
- };
- return (model, picture);
- }
- public virtual async Task UpdateCategoryPicture(CategoryModel.PictureModel model)
- {
- var picture = await _pictureService.GetPictureById(model.Id);
- if (picture == null)
- throw new ArgumentException("No picture found with the specified id");
-
- //Update picture fields
- await _pictureService.UpdatField(picture, x => x.AltAttribute, model.AltAttribute);
- await _pictureService.UpdatField(picture, x => x.TitleAttribute, model.TitleAttribute);
- await _pictureService.UpdatField(picture, x => x.Locales, model.Locales.ToTranslationProperty());
- }
-
public virtual async Task<(IEnumerable<CategoryModel.CategoryProductModel> categoryProductModels, int totalCount)> PrepareCategoryProductModel(string categoryId, int pageIndex, int pageSize)
{
var productCategories = await _productCategoryService.GetProductCategoriesByCategoryId(categoryId,
@@ -280,8 +253,7 @@ namespace Grand.Web.Admin.Services
var categoryproducts = new List<CategoryModel.CategoryProductModel>();
foreach (var item in productCategories)
{
- var pc = new CategoryModel.CategoryProductModel
- {
+ var pc = new CategoryModel.CategoryProductModel {
Id = item.Id,
CategoryId = item.CategoryId,
ProductId = item.ProductId,
@@ -347,8 +319,7 @@ namespace Grand.Web.Admin.Services
if (product.ProductCategories.Where(x => x.CategoryId == model.CategoryId).Count() == 0)
{
await _productCategoryService.InsertProductCategory(
- new ProductCategory
- {
+ new ProductCategory {
CategoryId = model.CategoryId,
IsFeaturedProduct = false,
DisplayOrder = 1,
@@ -364,8 +335,7 @@ namespace Grand.Web.Admin.Services
foreach (var item in activityLog)
{
var customer = await _customerService.GetCustomerById(item.CustomerId);
- var m = new CategoryModel.ActivityLogModel
- {
+ var m = new CategoryModel.ActivityLogModel {
Id = item.Id,
ActivityLogTypeName = (await _customerActivityService.GetActivityTypeById(item.ActivityLogTypeId))?.Name,
Comment = item.Comment,
diff --git a/src/Web/Grand.Web.Admin/Services/PictureViewModelService.cs b/src/Web/Grand.Web.Admin/Services/PictureViewModelService.cs
new file mode 100644
index 000000000..048e7322e
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Services/PictureViewModelService.cs
@@ -0,0 +1,70 @@
+using Grand.Business.Common.Extensions;
+using Grand.Business.Common.Interfaces.Localization;
+using Grand.Business.Storage.Interfaces;
+using Grand.Web.Admin.Extensions;
+using Grand.Web.Admin.Interfaces;
+using Grand.Web.Admin.Models.Common;
+using System;
+using System.Threading.Tasks;
+
+namespace Grand.Web.Admin.Services
+{
+ public class PictureViewModelService : IPictureViewModelService
+ {
+ private readonly IPictureService _pictureService;
+ private readonly ILanguageService _languageService;
+
+ public PictureViewModelService(IPictureService pictureService, ILanguageService languageService)
+ {
+ _pictureService = pictureService;
+ _languageService = languageService;
+ }
+
+ public virtual async Task<PictureModel> PreparePictureModel(string pictureId, string objectId)
+ {
+ if (string.IsNullOrEmpty(pictureId))
+ throw new ArgumentNullException(nameof(pictureId));
+
+ if (string.IsNullOrEmpty(objectId))
+ throw new ArgumentNullException(nameof(objectId));
+
+ var picture = await _pictureService.GetPictureById(pictureId);
+ if (picture == null)
+ throw new ArgumentNullException(nameof(picture));
+
+ var model = new PictureModel {
+ Id = picture.Id,
+ ObjectId = objectId,
+ PictureUrl = picture != null ? await _pictureService.GetPictureUrl(picture) : null,
+ AltAttribute = picture?.AltAttribute,
+ TitleAttribute = picture?.TitleAttribute,
+ };
+
+ foreach (var language in await _languageService.GetAllLanguages(true))
+ {
+ var locale = new PictureModel.PictureLocalizedModel();
+ locale.LanguageId = language.Id;
+ locale.AltAttribute = picture.GetTranslation(x => x.AltAttribute, language.Id, false);
+ locale.TitleAttribute = picture.GetTranslation(x => x.TitleAttribute, language.Id, false);
+ model.Locales.Add(locale);
+ }
+
+ return model;
+ }
+
+ public virtual async Task UpdatePicture(PictureModel model)
+ {
+ if (model == null)
+ throw new ArgumentNullException(nameof(model));
+
+ var picture = await _pictureService.GetPictureById(model.Id);
+ if (picture == null)
+ throw new ArgumentNullException(nameof(picture));
+
+ //Update picture fields
+ await _pictureService.UpdatField(picture, x => x.AltAttribute, model.AltAttribute);
+ await _pictureService.UpdatField(picture, x => x.TitleAttribute, model.TitleAttribute);
+ await _pictureService.UpdatField(picture, x => x.Locales, model.Locales.ToTranslationProperty());
+ }
+ }
+}
diff --git a/src/Web/Grand.Web.Admin/Startup/StartupApplication.cs b/src/Web/Grand.Web.Admin/Startup/StartupApplication.cs
index a1918def6..bb9f56936 100644
--- a/src/Web/Grand.Web.Admin/Startup/StartupApplication.cs
+++ b/src/Web/Grand.Web.Admin/Startup/StartupApplication.cs
@@ -49,6 +49,7 @@ namespace Grand.Web.Admin.Startup
services.AddScoped<IStoreViewModelService, StoreViewModelService>();
services.AddScoped<IBrandViewModelService, BrandViewModelService>();
services.AddScoped<IProductViewModelService, ProductViewModelService>();
+ services.AddScoped<IPictureViewModelService, PictureViewModelService>();
}
public void Configure(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment)
{
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
index 8e1c346e5..4305c0435 100644
--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
@@ -2079,15 +2079,6 @@
<Resource Name="Admin.Catalog.Brands.Permisions">
<Value>You can't edit this brand, because it can be used in many stores.</Value>
</Resource>
- <Resource Name="Admin.Catalog.Brands.Picture">
- <Value>Picture</Value>
- </Resource>
- <Resource Name="Admin.Catalog.Brands.Picture.Fields.AltAttribute">
- <Value>Picture alternate text</Value>
- </Resource>
- <Resource Name="Admin.Catalog.Brands.Picture.Fields.TitleAttribute">
- <Value>Picture title</Value>
- </Resource>
<Resource Name="Admin.Catalog.Brands.Updated">
<Value>The brand has been updated successfully.</Value>
</Resource>
@@ -2310,15 +2301,6 @@
<Resource Name="Admin.Catalog.Categories.Permisions">
<Value>You can't edit this category, because it can be used in many stores.</Value>
</Resource>
- <Resource Name="Admin.Catalog.Categories.Picture">
- <Value>Picture</Value>
- </Resource>
- <Resource Name="Admin.Catalog.Categories.Picture.Fields.AltAttribute">
- <Value>Picture alternate text</Value>
- </Resource>
- <Resource Name="Admin.Catalog.Categories.Picture.Fields.TitleAttribute">
- <Value>Picture title</Value>
- </Resource>
<Resource Name="Admin.Catalog.Categories.Products">
<Value>Products</Value>
</Resource>
@@ -2508,6 +2490,15 @@
<Resource Name="Admin.Catalog.Collections.Updated">
<Value>The collection has been updated successfully.</Value>
</Resource>
+ <Resource Name="Admin.Catalog.Picture">
+ <Value>Picture</Value>
+ </Resource>
+ <Resource Name="Admin.Catalog.Picture.Fields.AltAttribute">
+ <Value>Picture alternate text</Value>
+ </Resource>
+ <Resource Name="Admin.Catalog.Picture.Fields.TitleAttribute">
+ <Value>Picture title</Value>
+ </Resource>
<Resource Name="Admin.Catalog.ProductReservations.CantDeleteWithOrder">
<Value>You can't delete reservation with the order</Value>
</Resource>