From b8f69bae410f1a88f09ed14d9755572e7df7ad70 Mon Sep 17 00:00:00 2001 From: gdlcf88 <47396430@qq.com> Date: Tue, 21 Apr 2020 01:40:38 +0800 Subject: [PATCH] Improved product creation page --- .../ProductsPermissionDefinitionProvider.cs | 2 +- .../Products/Dtos/CreateUpdateProductDto.cs | 4 +++ .../Products/Products/Dtos/ProductDto.cs | 2 ++ .../ProductsApplicationAutoMapperProfile.cs | 4 ++- .../Products/Product/CreateModal.cshtml | 1 + .../Products/Product/CreateModal.cshtml.cs | 28 ++++++++++++++++++- .../ProductsWebAutoMapperProfile.cs | 2 +- 7 files changed, 39 insertions(+), 4 deletions(-) diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Authorization/ProductsPermissionDefinitionProvider.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Authorization/ProductsPermissionDefinitionProvider.cs index ff7304c2..6268ab5e 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Authorization/ProductsPermissionDefinitionProvider.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Authorization/ProductsPermissionDefinitionProvider.cs @@ -11,7 +11,7 @@ namespace EasyAbp.EShop.Products.Authorization { var moduleGroup = context.AddGroup(ProductsPermissions.GroupName, L("Permission:Products")); - var productTypes = moduleGroup.AddPermission(ProductsPermissions.ProductTypes.Default, L("Permission:ProductType"), MultiTenancySides.Host); + var productTypes = moduleGroup.AddPermission(ProductsPermissions.ProductTypes.Default, L("Permission:ProductType")); productTypes.AddChild(ProductsPermissions.ProductTypes.Create, L("Permission:Create"), MultiTenancySides.Host); productTypes.AddChild(ProductsPermissions.ProductTypes.Update, L("Permission:Update"), MultiTenancySides.Host); productTypes.AddChild(ProductsPermissions.ProductTypes.Delete, L("Permission:Delete"), MultiTenancySides.Host); diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/CreateUpdateProductDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/CreateUpdateProductDto.cs index b5db2d36..866f6979 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/CreateUpdateProductDto.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/CreateUpdateProductDto.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; @@ -13,6 +14,9 @@ namespace EasyAbp.EShop.Products.Products.Dtos [DisplayName("ProductProductTypeId")] public Guid ProductTypeId { get; set; } + [DisplayName("ProductCategory")] + public IEnumerable CategoryIds { get; set; } + [Required] [DisplayName("ProductDisplayName")] public string DisplayName { get; set; } diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ProductDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ProductDto.cs index 3d7bde21..f36bf6e2 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ProductDto.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ProductDto.cs @@ -10,6 +10,8 @@ namespace EasyAbp.EShop.Products.Products.Dtos public Guid ProductTypeId { get; set; } + public IEnumerable CategoryIds { get; set; } + public string DisplayName { get; set; } public InventoryStrategy InventoryStrategy { get; set; } 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 e8f06b38..bb725994 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 @@ -18,12 +18,14 @@ namespace EasyAbp.EShop.Products /* You can configure your AutoMapper mapping configuration here. * Alternatively, you can split your mapping configurations * into multiple profile classes for a better organization. */ - CreateMap(); + CreateMap() + .Ignore(dto => dto.CategoryIds); CreateMap(); CreateMap(); CreateMap(); CreateMap(); CreateMap(MemberList.Source) + .ForSourceMember(dto => dto.CategoryIds, opt => opt.DoNotValidate()) .Ignore(p => p.ProductDetail) .Ignore(p => p.ProductAttributes) .Ignore(p => p.ProductSkus); diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml index ebb253a1..c32dc4ac 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml @@ -9,6 +9,7 @@ + diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml.cs index 551365cc..53f33768 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/CreateModal.cshtml.cs @@ -1,7 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using EasyAbp.EShop.Products.Categories; +using EasyAbp.EShop.Products.Categories.Dtos; using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products.Dtos; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; +using Volo.Abp.Application.Dtos; namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product { @@ -9,14 +16,33 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product { [BindProperty] public CreateUpdateProductDto Product { get; set; } + + public IEnumerable Categories { get; set; } + private readonly ICategoryAppService _categoryAppService; private readonly IProductAppService _service; - public CreateModalModel(IProductAppService service) + public CreateModalModel( + ICategoryAppService categoryAppService, + IProductAppService service) { + _categoryAppService = categoryAppService; _service = service; } + public async Task OnGetAsync(Guid? storeId) + { + Categories = + (await _categoryAppService.GetListAsync(new PagedAndSortedResultRequestDto + {MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount}))?.Items + .Select(dto => new SelectListItem(dto.DisplayName, dto.Id.ToString())); + + Product = new CreateUpdateProductDto + { + StoreId = storeId + }; + } + public async Task OnPostAsync() { await _service.CreateAsync(Product); diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/ProductsWebAutoMapperProfile.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/ProductsWebAutoMapperProfile.cs index 32e39752..2391286e 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/ProductsWebAutoMapperProfile.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/ProductsWebAutoMapperProfile.cs @@ -1,4 +1,4 @@ -using EasyAbp.EShop.Products.Products.Dtos; +using EasyAbp.EShop.Products.Products.Dtos; using EasyAbp.EShop.Products.Categories.Dtos; using EasyAbp.EShop.Products.ProductTypes.Dtos; using AutoMapper;