Browse Source

Close #59: Remove CategoryIds property from ProductDto

pull/87/head
gdlcf88 6 years ago
parent
commit
511f9eef36
  1. 20
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/CreateUpdateProductCategoryDto.cs
  2. 12
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/GetProductCategoryListDto.cs
  3. 6
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/IProductCategoryAppService.cs
  4. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ProductDto.cs
  5. 50
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs
  6. 20
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
  7. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs
  8. 6
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/Product.cs
  9. 11
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/Product/EditModal.cshtml.cs
  10. 5
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/ProductsWebAutoMapperProfile.cs

20
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductCategories/Dtos/CreateUpdateProductCategoryDto.cs

@ -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; }
}
}

12
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; }
}
}

6
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>
{
}

2
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<Guid> CategoryIds { get; set; }
public string Code { get; set; }
public string DisplayName { get; set; }

50
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<ProductCategory, ProductCategoryDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateProductCategoryDto, CreateUpdateProductCategoryDto>,
public class ProductCategoryAppService : CrudAppService<ProductCategory, ProductCategoryDto, Guid, GetProductCategoryListDto, object, object>,
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<ProductCategory> 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<ProductCategoryDto> GetAsync(Guid id)
{
throw new NotSupportedException();
}
[RemoteService(false)]
public override Task<ProductCategoryDto> CreateAsync(object input)
{
throw new NotSupportedException();
}
[RemoteService(false)]
public override Task<ProductCategoryDto> UpdateAsync(Guid id, object input)
{
throw new NotSupportedException();
}
[RemoteService(false)]
public override Task DeleteAsync(Guid id)
{
throw new NotSupportedException();
}
}
}

20
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<ProductDto> 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;
}

7
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<Product, ProductDto>()
.Ignore(dto => dto.CategoryIds)
.Ignore(dto => dto.MinimumPrice)
.Ignore(dto => dto.MaximumPrice);
CreateMap<ProductDetail, ProductDetailDto>();
@ -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<CreateUpdateProductDetailDto, ProductDetail>(MemberList.Source)
.ForSourceMember(dto => dto.StoreId, opt => opt.DoNotValidate());
CreateMap<CreateUpdateProductAttributeDto, ProductAttribute>(MemberList.Source);
@ -50,7 +52,6 @@ namespace EasyAbp.EShop.Products
CreateMap<ProductType, ProductTypeDto>();
CreateMap<CreateUpdateProductTypeDto, ProductType>(MemberList.Source);
CreateMap<ProductCategory, ProductCategoryDto>();
CreateMap<CreateUpdateProductCategoryDto, ProductCategory>(MemberList.Source);
CreateMap<ProductHistory, ProductHistoryDto>();
CreateMap<ProductDetailHistory, ProductDetailHistoryDto>();
}

6
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<ProductSku>();
}
public void InitializeNullCollections()
{
ProductAttributes ??= new List<ProductAttribute>();
ProductSkus ??= new List<ProductSku>();
}
public void TrimCode()
{
Code = Code?.Trim();

11
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, CreateEditProductViewModel>(productDto);
Product.CategoryIds = (await _productCategoryAppService.GetListAsync(new GetProductCategoryListDto
{
ProductId = productDto.Id,
MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount
})).Items.Select(x => x.CategoryId).ToList();
Product.ProductDetail = new CreateEditProductDetailViewModel
{

5
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<ProductDto, CreateEditProductViewModel>()
.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,

Loading…
Cancel
Save