public async Task <ApiRequestResult> UpdateAsync([FromRoute] Guid productId, List <ProductSkuStockDto> dtos) { var list = new List <ProductSkuStock>(); dtos.ForEach(c => { var entity = c.EntityMap <ProductSkuStockDto, ProductSkuStock>(); list.Add(entity); }); await _productSkuStockRepository.DeleteAsync(c => c.ProductId == productId, false); await _productSkuStockRepository.MultiAddAsync(list); return(ApiRequestResult.Success("修改成功")); }
public async Task UpdateAsync(ProductDto dto) { try { //var productInfo = await _productRepository.GetAsync(dto.Id.Value); var productInfo = dto.EntityMap <ProductDto, Products>(); await _productRepository.UpdateAsync(productInfo); //会员价格信息 var memberPriceList = new List <ProductMemberPrice>(); foreach (var memberPrice in dto.MemberPriceList) { var memberPriceEntity = memberPrice.EntityMap <ProductMemberPriceDto, ProductMemberPrice>(); memberPriceEntity.ProductId = dto.Id.Value; memberPriceList.Add(memberPriceEntity); } await _productMemberPriceRepository.DeleteAsync(c => c.ProductId == dto.Id.Value, false); await _productMemberPriceRepository.MultiAddAsync(memberPriceList); //await _productMemberPriceRepository.MultiUpdateAsync(memberPriceList); //满减信息 var fullReductionList = new List <ProductFullReduction>(); foreach (var fullReduction in dto.ProductFullReductionList) { var fullReductionEntity = fullReduction.EntityMap <ProductFullReductionDto, ProductFullReduction>(); fullReductionEntity.ProductId = dto.Id.Value; fullReductionList.Add(fullReductionEntity); } await _productFullReductionRepository.DeleteAsync(c => c.ProductId == dto.Id.Value, false); await _productFullReductionRepository.MultiAddAsync(fullReductionList); //梯级价格 var productLadderList = new List <ProductLadder>(); foreach (var productLadder in dto.ProductLadderList) { var ladderEntity = productLadder.EntityMap <ProductLadderDto, ProductLadder>(); ladderEntity.ProductId = dto.Id.Value; productLadderList.Add(ladderEntity); } await _productLadderRepository.DeleteAsync(c => c.ProductId == dto.Id.Value, false); await _productLadderRepository.MultiAddAsync(productLadderList); //属性值 var attributeValueList = new List <ProductAttributeValue>(); foreach (var attributeValue in dto.ProductAttributeValueList) { var attributeValueEntity = attributeValue.EntityMap <ProductAttributeValueDto, ProductAttributeValue>(); attributeValueEntity.ProductId = dto.Id.Value; attributeValueList.Add(attributeValueEntity); } await _productAttributeValueRepository.DeleteAsync(c => c.ProductId == dto.Id.Value, false); await _productAttributeValueRepository.MultiAddAsync(attributeValueList); //库存信息 var skuStockList = new List <ProductSkuStock>(); foreach (var skuStock in dto.SkuStockList) { var skuStockEntity = skuStock.EntityMap <ProductSkuStockDto, ProductSkuStock>(); skuStockEntity.ProductId = dto.Id.Value; skuStockList.Add(skuStockEntity); } await _productSkuStockRepository.DeleteAsync(c => c.ProductId == dto.Id.Value, false); await _productSkuStockRepository.MultiAddAsync(skuStockList); } catch (Exception ex) { throw; } }