diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/CreateUpdateProductCategoryDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/CreateUpdateProductCategoryDto.cs deleted file mode 100644 index 2f076e9f..00000000 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/CreateUpdateProductCategoryDto.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; - -namespace EasyAbp.EShop.Products.ProductCategories.Dtos -{ - public class CreateUpdateProductCategoryDto - { - [Required] - [DisplayName("ProductCategoryCategoryId")] - public Guid CategoryId { get; set; } - - [Required] - [DisplayName("ProductCategoryProductId")] - public Guid ProductId { get; set; } - - [DisplayName("ProductCategoryDisplayOrder")] - public int DisplayOrder { get; set; } - } -} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/GetProductCategoryListDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/GetProductCategoryListDto.cs new file mode 100644 index 00000000..3cae3ecd --- /dev/null +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/GetProductCategoryListDto.cs @@ -0,0 +1,12 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace EasyAbp.EShop.Products.ProductCategories.Dtos +{ + public class GetProductCategoryListDto : PagedAndSortedResultRequestDto + { + public Guid? CategoryId { get; set; } + + public Guid? ProductId { get; set; } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/IProductCategoryAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/IProductCategoryAppService.cs index feb53235..86d0767d 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/IProductCategoryAppService.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/IProductCategoryAppService.cs @@ -9,9 +9,9 @@ namespace EasyAbp.EShop.Products.ProductCategories ICrudAppService< ProductCategoryDto, Guid, - PagedAndSortedResultRequestDto, - CreateUpdateProductCategoryDto, - CreateUpdateProductCategoryDto> + GetProductCategoryListDto, + object, + object> { } 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 3a0289c3..8a4129bb 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 @@ -11,8 +11,6 @@ namespace EasyAbp.EShop.Products.Products.Dtos public Guid ProductDetailId { get; set; } - public ICollection CategoryIds { get; set; } - public string Code { get; set; } public string DisplayName { get; set; } diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs index bb70df4b..15de0d49 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs @@ -1,18 +1,17 @@ using System; +using System.Linq; +using System.Threading.Tasks; using EasyAbp.EShop.Products.Authorization; using EasyAbp.EShop.Products.ProductCategories.Dtos; +using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; namespace EasyAbp.EShop.Products.ProductCategories { - public class ProductCategoryAppService : CrudAppService, + public class ProductCategoryAppService : CrudAppService, IProductCategoryAppService { - protected override string CreatePolicyName { get; set; } = ProductsPermissions.Products.Create; - protected override string DeletePolicyName { get; set; } = ProductsPermissions.Products.Delete; - protected override string UpdatePolicyName { get; set; } = ProductsPermissions.Products.Update; - protected override string GetPolicyName { get; set; } = ProductsPermissions.Products.Default; protected override string GetListPolicyName { get; set; } = ProductsPermissions.Products.Default; private readonly IProductCategoryRepository _repository; @@ -21,5 +20,46 @@ namespace EasyAbp.EShop.Products.ProductCategories { _repository = repository; } + + protected override IQueryable CreateFilteredQuery(GetProductCategoryListDto input) + { + var queryable = Repository.AsQueryable(); + + if (input.CategoryId.HasValue) + { + queryable = queryable.Where(x => x.CategoryId == input.CategoryId); + } + + if (input.ProductId.HasValue) + { + queryable = queryable.Where(x => x.ProductId == input.ProductId); + } + + return queryable; + } + + [RemoteService(false)] + public override Task GetAsync(Guid id) + { + throw new NotSupportedException(); + } + + [RemoteService(false)] + public override Task CreateAsync(object input) + { + throw new NotSupportedException(); + } + + [RemoteService(false)] + public override Task UpdateAsync(Guid id, object input) + { + throw new NotSupportedException(); + } + + [RemoteService(false)] + public override Task DeleteAsync(Guid id) + { + throw new NotSupportedException(); + } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs index 47c77678..d08179b6 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs @@ -59,6 +59,13 @@ namespace EasyAbp.EShop.Products.Products return input.ShowHidden ? query : query.Where(x => !x.IsHidden); } + protected override Product MapToEntity(CreateUpdateProductDto createInput) + { + var product = base.MapToEntity(createInput); + + return product; + } + public override async Task CreateAsync(CreateUpdateProductDto input) { await CheckCreatePolicyAsync(); @@ -203,9 +210,6 @@ namespace EasyAbp.EShop.Products.Products await LoadRealInventoriesAsync(product, dto, storeId); await LoadPricesAsync(product, dto, storeId); - dto.CategoryIds = (await _productCategoryRepository.GetListByProductIdAsync(dto.Id)) - .Select(x => x.CategoryId).ToList(); - return dto; } @@ -224,9 +228,6 @@ namespace EasyAbp.EShop.Products.Products await LoadRealInventoriesAsync(product, dto, storeId); - dto.CategoryIds = (await _productCategoryRepository.GetListByProductIdAsync(dto.Id)) - .Select(x => x.CategoryId).ToList(); - return dto; } @@ -292,8 +293,11 @@ namespace EasyAbp.EShop.Products.Products product.ProductSkus.Single(sku => sku.Id == productSkuDto.Id), storeId); } - productDto.MinimumPrice = productDto.ProductSkus.Select(sku => sku.Price).Min(); - productDto.MaximumPrice = productDto.ProductSkus.Select(sku => sku.Price).Max(); + if (productDto.ProductSkus.Count > 0) + { + productDto.MinimumPrice = productDto.ProductSkus.Min(sku => sku.Price); + productDto.MaximumPrice = productDto.ProductSkus.Max(sku => sku.Price); + } return productDto; } 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 4775b03c..83325cd2 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 @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products.Dtos; using EasyAbp.EShop.Products.Categories; @@ -25,7 +27,6 @@ namespace EasyAbp.EShop.Products * Alternatively, you can split your mapping configurations * into multiple profile classes for a better organization. */ CreateMap() - .Ignore(dto => dto.CategoryIds) .Ignore(dto => dto.MinimumPrice) .Ignore(dto => dto.MaximumPrice); CreateMap(); @@ -38,7 +39,8 @@ namespace EasyAbp.EShop.Products .ForSourceMember(dto => dto.StoreId, opt => opt.DoNotValidate()) .ForSourceMember(dto => dto.CategoryIds, opt => opt.DoNotValidate()) .Ignore(p => p.ProductAttributes) - .Ignore(p => p.ProductSkus); + .Ignore(p => p.ProductSkus) + .AfterMap((src, dest) => dest.InitializeNullCollections()); CreateMap(MemberList.Source) .ForSourceMember(dto => dto.StoreId, opt => opt.DoNotValidate()); CreateMap(MemberList.Source); @@ -50,7 +52,6 @@ namespace EasyAbp.EShop.Products CreateMap(); CreateMap(MemberList.Source); CreateMap(); - CreateMap(MemberList.Source); CreateMap(); CreateMap(); } diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/Product.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/Product.cs index 22787762..67d5f1f6 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/Product.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/Product.cs @@ -68,6 +68,12 @@ namespace EasyAbp.EShop.Products.Products ProductSkus = new List(); } + public void InitializeNullCollections() + { + ProductAttributes ??= new List(); + ProductSkus ??= new List(); + } + public void TrimCode() { Code = Code?.Trim(); diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/EditModal.cshtml.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/EditModal.cshtml.cs index 6244d478..0663b796 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/EditModal.cshtml.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/EditModal.cshtml.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Threading.Tasks; using EasyAbp.EShop.Products.Categories; using EasyAbp.EShop.Products.Categories.Dtos; +using EasyAbp.EShop.Products.ProductCategories; +using EasyAbp.EShop.Products.ProductCategories.Dtos; using EasyAbp.EShop.Products.ProductDetails; using EasyAbp.EShop.Products.ProductDetails.Dtos; using Microsoft.AspNetCore.Mvc; @@ -32,17 +34,20 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product private readonly IProductTypeAppService _productTypeAppService; private readonly ICategoryAppService _categoryAppService; private readonly IProductDetailAppService _productDetailAppService; + private readonly IProductCategoryAppService _productCategoryAppService; private readonly IProductAppService _service; public EditModalModel( IProductTypeAppService productTypeAppService, ICategoryAppService categoryAppService, IProductDetailAppService productDetailAppService, + IProductCategoryAppService productCategoryAppService, IProductAppService service) { _productTypeAppService = productTypeAppService; _categoryAppService = categoryAppService; _productDetailAppService = productDetailAppService; + _productCategoryAppService = productCategoryAppService; _service = service; } @@ -63,6 +68,12 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.Product var detailDto = await _productDetailAppService.GetAsync(productDto.ProductDetailId); Product = ObjectMapper.Map(productDto); + + Product.CategoryIds = (await _productCategoryAppService.GetListAsync(new GetProductCategoryListDto + { + ProductId = productDto.Id, + MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount + })).Items.Select(x => x.CategoryId).ToList(); Product.ProductDetail = new CreateEditProductDetailViewModel { 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 389f8af0..431171a2 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 @@ -20,8 +20,9 @@ namespace EasyAbp.EShop.Products.Web * Alternatively, you can split your mapping configurations * into multiple profile classes for a better organization. */ CreateMap() - .Ignore(dto => dto.ProductDetail) - .Ignore(dto => dto.StoreId) + .Ignore(model => model.CategoryIds) + .Ignore(model => model.ProductDetail) + .Ignore(model => model.StoreId) .ForSourceMember(dto => dto.ProductDetailId, opt => opt.DoNotValidate()) // .Ignore(x => x.ProductAttributes); .ForMember(dest => dest.ProductAttributeNames,