From c6e3846a9f08f2ff1c77fe5ced267e9d83153374 Mon Sep 17 00:00:00 2001 From: KrzysztofPajak Date: Wed, 22 Sep 2021 19:49:03 +0200 Subject: [PATCH] Admin panel - Admin search - use automapper --- .../Controllers/SettingController.cs | 56 +------------------ .../AdminSearchSettingsMappingExtensions.cs | 18 ++++++ .../Mapper/AdminSearchSettingsProfile.cs | 18 ++++++ 3 files changed, 38 insertions(+), 54 deletions(-) create mode 100644 src/Web/Grand.Web.Admin/Extensions/Mapping/Settings/AdminSearchSettingsMappingExtensions.cs create mode 100644 src/Web/Grand.Web.Admin/Mapper/AdminSearchSettingsProfile.cs diff --git a/src/Web/Grand.Web.Admin/Controllers/SettingController.cs b/src/Web/Grand.Web.Admin/Controllers/SettingController.cs index b7999782a..d414c625f 100644 --- a/src/Web/Grand.Web.Admin/Controllers/SettingController.cs +++ b/src/Web/Grand.Web.Admin/Controllers/SettingController.cs @@ -907,34 +907,7 @@ private void SavePushNotificationsToFile(PushNotificationsSettingsModel model) public IActionResult AdminSearch() { var settings = _settingService.LoadSetting(); - var model = new AdminSearchSettingsModel { - SearchInBlogs = settings.SearchInBlogs, - SearchInCategories = settings.SearchInCategories, - SearchInCustomers = settings.SearchInCustomers, - SearchInCollections = settings.SearchInCollections, - SearchInNews = settings.SearchInNews, - SearchInOrders = settings.SearchInOrders, - SearchInProducts = settings.SearchInProducts, - SearchInPages = settings.SearchInPages, - MinSearchTermLength = settings.MinSearchTermLength, - MaxSearchResultsCount = settings.MaxSearchResultsCount, - ProductsDisplayOrder = settings.ProductsDisplayOrder, - CategoriesDisplayOrder = settings.CategoriesDisplayOrder, - CollectionsDisplayOrder = settings.CollectionsDisplayOrder, - PagesDisplayOrder = settings.PagesDisplayOrder, - NewsDisplayOrder = settings.NewsDisplayOrder, - BlogsDisplayOrder = settings.BlogsDisplayOrder, - CustomersDisplayOrder = settings.CustomersDisplayOrder, - OrdersDisplayOrder = settings.OrdersDisplayOrder, - SearchInMenu = settings.SearchInMenu, - MenuDisplayOrder = settings.MenuDisplayOrder, - CategorySizeLimit = settings.CategorySizeLimit, - BrandSizeLimit = settings.BrandSizeLimit, - CollectionSizeLimit = settings.CollectionSizeLimit, - VendorSizeLimit = settings.VendorSizeLimit, - CustomerGroupSizeLimit = settings.CustomerGroupSizeLimit - }; - + var model = settings.ToModel(); return View(model); } @@ -943,32 +916,7 @@ public IActionResult AdminSearch() public async Task AdminSearch(AdminSearchSettingsModel model) { var settings = _settingService.LoadSetting(); - settings.SearchInBlogs = model.SearchInBlogs; - settings.SearchInCategories = model.SearchInCategories; - settings.SearchInCustomers = model.SearchInCustomers; - settings.SearchInCollections = model.SearchInCollections; - settings.SearchInNews = model.SearchInNews; - settings.SearchInOrders = model.SearchInOrders; - settings.SearchInProducts = model.SearchInProducts; - settings.SearchInPages = model.SearchInPages; - settings.MinSearchTermLength = model.MinSearchTermLength; - settings.MaxSearchResultsCount = model.MaxSearchResultsCount; - settings.ProductsDisplayOrder = model.ProductsDisplayOrder; - settings.CategoriesDisplayOrder = model.CategoriesDisplayOrder; - settings.CollectionsDisplayOrder = model.CollectionsDisplayOrder; - settings.PagesDisplayOrder = model.PagesDisplayOrder; - settings.NewsDisplayOrder = model.NewsDisplayOrder; - settings.BlogsDisplayOrder = model.BlogsDisplayOrder; - settings.CustomersDisplayOrder = model.CustomersDisplayOrder; - settings.OrdersDisplayOrder = model.OrdersDisplayOrder; - settings.SearchInMenu = model.SearchInMenu; - settings.MenuDisplayOrder = model.MenuDisplayOrder; - settings.CategorySizeLimit = model.CategorySizeLimit; - settings.BrandSizeLimit = model.BrandSizeLimit; - settings.CollectionSizeLimit = model.CollectionSizeLimit; - settings.VendorSizeLimit = model.VendorSizeLimit; - settings.CustomerGroupSizeLimit = model.CustomerGroupSizeLimit; - + settings = model.ToEntity(settings); await _settingService.SaveSetting(settings); //now clear cache diff --git a/src/Web/Grand.Web.Admin/Extensions/Mapping/Settings/AdminSearchSettingsMappingExtensions.cs b/src/Web/Grand.Web.Admin/Extensions/Mapping/Settings/AdminSearchSettingsMappingExtensions.cs new file mode 100644 index 000000000..a02b88f81 --- /dev/null +++ b/src/Web/Grand.Web.Admin/Extensions/Mapping/Settings/AdminSearchSettingsMappingExtensions.cs @@ -0,0 +1,18 @@ +using Grand.Domain.AdminSearch; +using Grand.Infrastructure.Mapper; +using Grand.Web.Admin.Models.Settings; + +namespace Grand.Web.Admin.Extensions +{ + public static class AdminSearchSettingsMappingExtensions + { + public static AdminSearchSettingsModel ToModel(this AdminSearchSettings entity) + { + return entity.MapTo(); + } + public static AdminSearchSettings ToEntity(this AdminSearchSettingsModel model, AdminSearchSettings destination) + { + return model.MapTo(destination); + } + } +} \ No newline at end of file diff --git a/src/Web/Grand.Web.Admin/Mapper/AdminSearchSettingsProfile.cs b/src/Web/Grand.Web.Admin/Mapper/AdminSearchSettingsProfile.cs new file mode 100644 index 000000000..1942adbcc --- /dev/null +++ b/src/Web/Grand.Web.Admin/Mapper/AdminSearchSettingsProfile.cs @@ -0,0 +1,18 @@ +using AutoMapper; +using Grand.Domain.AdminSearch; +using Grand.Infrastructure.Mapper; +using Grand.Web.Admin.Models.Settings; + +namespace Grand.Web.Admin.Mapper +{ + public class AdminSearchSettingsProfile : Profile, IAutoMapperProfile + { + public AdminSearchSettingsProfile() + { + CreateMap(); + CreateMap(); + } + + public int Order => 0; + } +} \ No newline at end of file