コード例 #1
0
        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;
            }
        }
コード例 #2
0
        public async Task AddAsync(ProductDto dto)
        {
            var productInfo = dto.EntityMap <ProductDto, Products>();

            productInfo.Id = Guid.NewGuid();
            await _productRepository.AddAsync(productInfo);


            //会员价格信息
            var memberPriceList = new List <ProductMemberPrice>();

            foreach (var memberPrice in dto.MemberPriceList)
            {
                var memberPriceEntity = memberPrice.EntityMap <ProductMemberPriceDto, ProductMemberPrice>();
                memberPriceEntity.ProductId = productInfo.Id;
                memberPriceList.Add(memberPriceEntity);
            }
            await _productMemberPriceRepository.MultiAddAsync(memberPriceList);

            //满减信息
            var fullReductionList = new List <ProductFullReduction>();

            foreach (var fullReduction in dto.ProductFullReductionList)
            {
                var fullReductionEntity = fullReduction.EntityMap <ProductFullReductionDto, ProductFullReduction>();
                fullReductionEntity.ProductId = productInfo.Id;
                fullReductionList.Add(fullReductionEntity);
            }
            await _productFullReductionRepository.MultiAddAsync(fullReductionList);

            //梯级价格
            var productLadderList = new List <ProductLadder>();

            foreach (var productLadder in dto.ProductLadderList)
            {
                var ladderEntity = productLadder.EntityMap <ProductLadderDto, ProductLadder>();
                ladderEntity.ProductId = productInfo.Id;
                productLadderList.Add(ladderEntity);
            }
            await _productLadderRepository.MultiAddAsync(productLadderList);

            //属性值
            var attributeValueList = new List <ProductAttributeValue>();

            foreach (var attributeValue in dto.ProductAttributeValueList)
            {
                var attributeValueEntity = attributeValue.EntityMap <ProductAttributeValueDto, ProductAttributeValue>();
                attributeValueEntity.ProductId = productInfo.Id;
                attributeValueList.Add(attributeValueEntity);
            }
            await _productAttributeValueRepository.MultiAddAsync(attributeValueList);


            //库存信息
            var skuStockList = new List <ProductSkuStock>();

            foreach (var skuStock in dto.SkuStockList)
            {
                var skuStockEntity = skuStock.EntityMap <ProductSkuStockDto, ProductSkuStock>();
                skuStockEntity.ProductId = productInfo.Id;
                skuStockList.Add(skuStockEntity);
            }
            await _productSkuStockRepository.MultiAddAsync(skuStockList);
        }