Exemplo n.º 1
0
        public CallResult AddProduct(string SPUName, string SPUDesc, List <string> SKUSpecs, List <string> SKUUnits, List <decimal> SKUDealerPrices, List <string> SKUImageUrles, List <decimal> SKUPvs)
        {
            var productSPUId = Guid.NewGuid();
            var productSKUs  = new List <ProductSKU>();

            for (int i = 0; i < SKUSpecs.Count; i++)
            {
                var productSKU = new ProductSKU().CreateProductSKU(
                    SPUName,
                    productSPUId,
                    SKUImageUrles[i],
                    SKUDealerPrices[i],
                    SKUPvs[i],
                    SKUUnits[i],
                    SKUSpecs[i]);
                productSKUs.Add(productSKU);
            }
            var productSPU = new ProductSPU().CreateProductSPU(productSPUId, SPUName, SPUDesc, productSKUs);

            try
            {
                using (baseRepository)
                {
                    productRepository.Add(productSPU);
                    baseRepository.Commit();
                }
                return(new CallResult(200, "产品创建成功"));
            }
            catch (Exception ex)
            {
                return(new CallResult(500, $"产品创建异常:{ex.Message}/r/n{ex.StackTrace}"));
            }
        }
        public ResultEntity <bool> AddProduct(AddProductSPUDto addProductSPUDto)
        {
            var productSPUGuid = Guid.NewGuid();
            var productSKU     = new List <ProductSKU>();
            int index          = 0;

            addProductSPUDto.SKUSpecs.ForEach((a) =>
            {
                productSKU.Add(new ProductSKU().CreateProductSKU(addProductSPUDto.SPUName, productSPUGuid,
                                                                 addProductSPUDto.SKUImages[index], addProductSPUDto.SKUDealerPrices[index],
                                                                 addProductSPUDto.SKUPV[index], addProductSPUDto.SKUUnits[index], addProductSPUDto.SKUSpecs[index]));
            });
            var productSPU = new ProductSPU().CreateProductSPU(productSPUGuid, addProductSPUDto.SPUName, addProductSPUDto.SPUDes, productSKU);

            try
            {
                using (_repositoryContext)
                {
                    _productRepository.CreateProduct(productSPU);
                    _repositoryContext.Commit();
                }
                return(GetResultEntity(true));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public ResultEntity <bool> AddProduct(AddProductSPUDTO addproductspudto)
        {
            var productspuid = Guid.NewGuid();
            var productskus  = new List <ProductSKU>();

            for (int i = 0; i < addproductspudto.SKUSpecs.Count; i++)
            {
                var productsku = new ProductSKU().CreateProductSKU(addproductspudto.SPUName,
                                                                   productspuid, addproductspudto.SKUImages[i], addproductspudto.SKUDealerPrices[i],
                                                                   addproductspudto.SKUPvs[i], addproductspudto.SKUUnits[i], addproductspudto.SKUSpecs[i]);
                productskus.Add(productsku);
            }
            var productspu = new ProductSPU().CreateProductSPU(productspuid, addproductspudto.SPUName,
                                                               addproductspudto.SPUDesc, productskus);

            try
            {
                using (irepositorycontext)
                {
                    iproductrepository.CreateProduct(productspu);
                    irepositorycontext.Commit();
                }
                return(GetResultEntity(true));
            }
            catch (Exception error)
            {
                throw error;
            }
        }