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; } }
public void AddProductTest() { #region ÄãºÃ aaa hh = f => { return(Math.Pow(f, 2)); }; var ff = hh(10); #endregion ÄãºÃ http = new HttpClient(); var fs = new FileStream(@"D:\GitHubProjects\Boss.DDD\Boss.DDD.Test\Img\photo.png", FileMode.Open, FileAccess.Read); var by = new byte[fs.Length]; fs.Read(by, 0, Convert.ToInt32(fs.Length)); fs.Close(); var addProductSPUDto = new AddProductSPUDto() { SPUName = "²âÊÔSPUÃû³Æ", SPUDes = "²âÊÔSPUÏêϸ", SKUSpecs = new List <string>() { "Âö¶¯500ºÁÉý", "Âö¶¯700ºÁÉý" }, SKUUnits = new List <string>() { "Æ¿", "Æ¿" }, SKUDealerPrices = new List <decimal>() { 100, 120 }, SKUImages = new List <byte[]>() { by, by }, SKUPV = new List <decimal>() { 120, 200 } }; var json = JsonConvert.SerializeObject(addProductSPUDto); HttpContent httpContent = new StringContent(json); httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var result = http.PostAsync("http://localhost:54309/api/Product/AddProduct", httpContent).Result; var val = result.Content.ReadAsStringAsync().Result; }
public ResultEntity <bool> AddProduct([FromBody] AddProductSPUDto addProductSPUDto) { var result = new ResultEntity <bool>(); var productDbContext = _serviceLocator.GetService <IProdcutContext>(); var repository = _serviceLocator.GetService <IRepository>(new ParameterOverrides() { { "dbContext", productDbContext } }); var productEFCoreRepository = _serviceLocator.GetService <IProductRepository>(new ParameterOverrides() { { "dbContext", productDbContext } }); ////创建产品EF 连接上下文 //var productDbContext = new ProdcutEFCoreContext(); ////EF仓储 //var repository = new EFCoreRepository(productDbContext); ////产品EF仓库 //var productEFCoreRepository = new ProductEFCoreRepository(productDbContext); ////添加产品SPU 服务用例 var addProductSPUUseCase = new AddProductSPUUseCase(repository, productEFCoreRepository); try { result = addProductSPUUseCase.AddProduct(addProductSPUDto); result.IsSuccess = true; result.Count = 1; result.Msg = "成功添加产品"; } catch (Exception ex) { result.ErrorCode = 100; result.Msg = ex.Message; } return(result); }