From 145cbfa6d6641df3c515caef18d3bbffbd722217 Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Fri, 13 Nov 2020 19:41:50 +0800 Subject: [PATCH] Improve category selection with EasyAbp.Abp.TagHelper --- common.props | 2 +- .../Categories/Dtos/CategorySummaryDto.cs | 18 ++++++++++++ .../Categories/ICategoryAppService.cs | 3 +- .../Products/Categories/CategoryAppService.cs | 28 ++++++++++++++++++- .../ProductsApplicationAutoMapperProfile.cs | 1 + .../EasyAbp/EShop/Products/ProductsConsts.cs | 6 ++++ .../Products/Categories/CategoryController.cs | 9 +++++- .../EShopProductsWebModule.cs | 8 ++++-- .../EasyAbp.EShop.Products.Web.csproj | 1 + .../ViewModels/CreateEditProductViewModel.cs | 8 +++++- 10 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Categories/Dtos/CategorySummaryDto.cs diff --git a/common.props b/common.props index 5d947988..a26e0cae 100644 --- a/common.props +++ b/common.props @@ -1,7 +1,7 @@ latest - 1.6.2 + 1.7.0 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Categories/Dtos/CategorySummaryDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Categories/Dtos/CategorySummaryDto.cs new file mode 100644 index 00000000..20c82a66 --- /dev/null +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Categories/Dtos/CategorySummaryDto.cs @@ -0,0 +1,18 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace EasyAbp.EShop.Products.Categories.Dtos +{ + public class CategorySummaryDto : EntityDto + { + public string UniqueName { get; set; } + + public string DisplayName { get; set; } + + public string TreedDisplayName { get; set; } + + public int Level { get; set; } + + public Guid? ParentId { get; set; } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Categories/ICategoryAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Categories/ICategoryAppService.cs index 9998caf1..693a741c 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Categories/ICategoryAppService.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Categories/ICategoryAppService.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using EasyAbp.EShop.Products.Categories.Dtos; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -13,6 +14,6 @@ namespace EasyAbp.EShop.Products.Categories CreateUpdateCategoryDto, CreateUpdateCategoryDto> { - + Task> GetSummaryListAsync(GetCategoryListDto input); } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Categories/CategoryAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Categories/CategoryAppService.cs index 992f2cd1..681d26af 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Categories/CategoryAppService.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Categories/CategoryAppService.cs @@ -1,9 +1,10 @@ using System; +using System.Collections.Generic; using System.Linq; +using System.Linq.Dynamic.Core; using System.Threading.Tasks; using EasyAbp.EShop.Products.Categories.Dtos; using EasyAbp.EShop.Products.Permissions; -using EasyAbp.EShop.Stores.Authorization; using Microsoft.AspNetCore.Authorization; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -42,5 +43,30 @@ namespace EasyAbp.EShop.Products.Categories return await base.GetListAsync(input); } + + public virtual async Task> GetSummaryListAsync(GetCategoryListDto input) + { + await CheckGetListPolicyAsync(); + + var query = _repository.AsQueryable(); + + var totalCount = await AsyncExecuter.CountAsync(query); + + query = query.OrderBy(x => x.Code); + + if (!input.Sorting.IsNullOrWhiteSpace()) + { + query = query.OrderBy(input.Sorting); + } + + query = query.PageBy(input.SkipCount, input.MaxResultCount); + + var categories = await AsyncExecuter.ToListAsync(query); + + return new PagedResultDto( + totalCount, + categories.Select(x => ObjectMapper.Map(x)).ToList() + ); + } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs index 4b562fb4..34f91769 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs @@ -61,6 +61,7 @@ namespace EasyAbp.EShop.Products await attributeOptionIdsSerializer.SerializeAsync(src.AttributeOptionIds))); CreateMap(MemberList.Source); CreateMap(); + CreateMap(); CreateMap(MemberList.Source); CreateMap(); CreateMap(); diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/ProductsConsts.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/ProductsConsts.cs index 9684e57f..d6575c13 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/ProductsConsts.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/ProductsConsts.cs @@ -7,5 +7,11 @@ public const string DefaultProductGroupDisplayName = "Default"; public const string DefaultProductGroupDescription = ""; + + public const string CategoryRouteBase = "/api/eShop/products/category"; + + public const string GetCategorySummaryListedDataSourceUrl = CategoryRouteBase + "/summary"; + + public const string GetCategorySummarySingleDataSourceUrl = CategoryRouteBase + "/{id}"; } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/Categories/CategoryController.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/Categories/CategoryController.cs index 4d23af9e..c60c88e4 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/Categories/CategoryController.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/Categories/CategoryController.cs @@ -8,7 +8,7 @@ using Volo.Abp.Application.Dtos; namespace EasyAbp.EShop.Products.Categories { [RemoteService(Name = "EasyAbpEShopProducts")] - [Route("/api/eShop/products/category")] + [Route(ProductsConsts.CategoryRouteBase)] public class CategoryController : ProductsController, ICategoryAppService { private readonly ICategoryAppService _service; @@ -50,5 +50,12 @@ namespace EasyAbp.EShop.Products.Categories { return _service.DeleteAsync(id); } + + [HttpGet] + [Route("summary")] + public async Task> GetSummaryListAsync(GetCategoryListDto input) + { + return await _service.GetSummaryListAsync(input); + } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/EShopProductsWebModule.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/EShopProductsWebModule.cs index 5cf97972..c1564bbf 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/EShopProductsWebModule.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/EShopProductsWebModule.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc.RazorPages; +using EasyAbp.Abp.TagHelperPlus; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.DependencyInjection; using EasyAbp.EShop.Products.Localization; using EasyAbp.EShop.Products.Web.Menus; @@ -14,8 +15,9 @@ namespace EasyAbp.EShop.Products.Web [DependsOn( typeof(EShopProductsHttpApiModule), typeof(AbpAspNetCoreMvcUiThemeSharedModule), - typeof(AbpAutoMapperModule) - )] + typeof(AbpAutoMapperModule), + typeof(AbpTagHelperPlusModule) + )] public class EShopProductsWebModule : AbpModule { public override void PreConfigureServices(ServiceConfigurationContext context) diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/EasyAbp.EShop.Products.Web.csproj b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/EasyAbp.EShop.Products.Web.csproj index 5030fb88..0229dfd5 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/EasyAbp.EShop.Products.Web.csproj +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/EasyAbp.EShop.Products.Web.csproj @@ -14,6 +14,7 @@ + diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateEditProductViewModel.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateEditProductViewModel.cs index 2755958f..fcdcd11c 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateEditProductViewModel.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/ViewModels/CreateEditProductViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using EasyAbp.Abp.TagHelperPlus.EasySelector; using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products.Dtos; using Microsoft.AspNetCore.Mvc; @@ -20,7 +21,12 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product.ViewM [Display(Name = "ProductProductGroupName")] public string ProductGroupName { get; set; } - [SelectItems("Categories")] + // [SelectItems("Categories")] + [EasySelector( + getListedDataSourceUrl: ProductsConsts.GetCategorySummaryListedDataSourceUrl, + getSingleDataSourceUrl: ProductsConsts.GetCategorySummarySingleDataSourceUrl, + keyPropertyName: "id", + textPropertyName: "displayName")] [Display(Name = "ProductCategory")] public List CategoryIds { get; set; }