public async Task <CreateProductResponse> CreateAsync(Product product) { CreateProductResponse response; var categoryExists = await _unitOfWork.Categories.AnyAsync(category => category.Id == product.CategoryId); if (!categoryExists) { _logger.LogWarning($"Category {product.CategoryId} was not found during product creation"); response = new CreateProductResponse(CreateProductResult.CategoryNotFound); return(response); } product = await _unitOfWork.Products.CreateAsync(product); await _unitOfWork.SaveAsync(); _logger.LogInformation($"Product {product.Id} was created"); response = new CreateProductResponse(product); return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateProductResponse response = new CreateProductResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("ProductViewDetail", targetDepth)) { var unmarshaller = ProductViewDetailUnmarshaller.Instance; response.ProductViewDetail = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ProvisioningArtifactDetail", targetDepth)) { var unmarshaller = ProvisioningArtifactDetailUnmarshaller.Instance; response.ProvisioningArtifactDetail = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Tags", targetDepth)) { var unmarshaller = new ListUnmarshaller <Tag, TagUnmarshaller>(TagUnmarshaller.Instance); response.Tags = unmarshaller.Unmarshall(context); continue; } } return(response); }
//输入产品名称和描述创建产品 private static void TestCreateProduct() { IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>"); DefaultAcsClient client = new DefaultAcsClient(clientProfile); CreateProductRequest request = new CreateProductRequest(); request.Name = "<productName>"; request.Desc = "<product description>"; try { CreateProductResponse response = client.GetAcsResponse(request); Console.WriteLine(response.Success); Console.WriteLine(response.ErrorMessage); CreateProductResponse.CreateProduct_ProductInfo ProductInfo = response.ProductInfo; Console.WriteLine("product name: " + ProductInfo.ProductName); Console.WriteLine("product key: " + ProductInfo.ProductKey); Console.WriteLine("product description: " + ProductInfo.ProductDesc); } catch (ServerException e) { Console.WriteLine(e.ErrorCode); Console.WriteLine(e.ErrorMessage); } catch (ClientException e) { Console.WriteLine(e.ErrorCode); Console.WriteLine(e.ErrorMessage); } Console.ReadKey(); }
public static CreateProductResponse Unmarshall(UnmarshallerContext context) { CreateProductResponse createProductResponse = new CreateProductResponse(); createProductResponse.HttpResponse = context.HttpResponse; createProductResponse.RequestId = context.StringValue("CreateProduct.RequestId"); createProductResponse.Success = context.BooleanValue("CreateProduct.Success"); createProductResponse.ErrorMessage = context.StringValue("CreateProduct.ErrorMessage"); CreateProductResponse.CreateProduct_ProductInfo productInfo = new CreateProductResponse.CreateProduct_ProductInfo(); productInfo.ProductKey = context.StringValue("CreateProduct.ProductInfo.ProductKey"); productInfo.ProductName = context.StringValue("CreateProduct.ProductInfo.ProductName"); productInfo.NodeType = context.IntegerValue("CreateProduct.ProductInfo.NodeType"); productInfo.CatId = context.LongValue("CreateProduct.ProductInfo.CatId"); productInfo.CreateUserId = context.LongValue("CreateProduct.ProductInfo.CreateUserId"); productInfo.ProductDesc = context.StringValue("CreateProduct.ProductInfo.ProductDesc"); productInfo.FromSource = context.StringValue("CreateProduct.ProductInfo.FromSource"); productInfo.ExtProps = context.StringValue("CreateProduct.ProductInfo.ExtProps"); productInfo.GmtCreate = context.StringValue("CreateProduct.ProductInfo.GmtCreate"); productInfo.GmtModified = context.StringValue("CreateProduct.ProductInfo.GmtModified"); productInfo.ProductSecret = context.StringValue("CreateProduct.ProductInfo.ProductSecret"); productInfo.Id2 = context.BooleanValue("CreateProduct.ProductInfo.Id2"); createProductResponse.ProductInfo = productInfo; return(createProductResponse); }
private CreateProductResponse Response(CreateProductRequest request) { var response = new CreateProductResponse(1, "basketball"); Logger.LogInformation($"接收消息:{System.Text.Json.JsonSerializer.Serialize(request)} 时间:{DateTimeOffset.Now}{Environment.NewLine}响应消息:{System.Text.Json.JsonSerializer.Serialize(response)}"); return(response); }
public static CreateProductResponse Unmarshall(UnmarshallerContext _ctx) { CreateProductResponse createProductResponse = new CreateProductResponse(); createProductResponse.HttpResponse = _ctx.HttpResponse; createProductResponse.RequestId = _ctx.StringValue("CreateProduct.RequestId"); createProductResponse.Success = _ctx.BooleanValue("CreateProduct.Success"); createProductResponse.Code = _ctx.StringValue("CreateProduct.Code"); createProductResponse.ErrorMessage = _ctx.StringValue("CreateProduct.ErrorMessage"); createProductResponse.ProductKey = _ctx.StringValue("CreateProduct.ProductKey"); CreateProductResponse.CreateProduct_Data data = new CreateProductResponse.CreateProduct_Data(); data.DataFormat = _ctx.IntegerValue("CreateProduct.Data.DataFormat"); data.Description = _ctx.StringValue("CreateProduct.Data.Description"); data.NodeType = _ctx.IntegerValue("CreateProduct.Data.NodeType"); data.ProductKey = _ctx.StringValue("CreateProduct.Data.ProductKey"); data.ProductName = _ctx.StringValue("CreateProduct.Data.ProductName"); data.AliyunCommodityCode = _ctx.StringValue("CreateProduct.Data.AliyunCommodityCode"); data.Id2 = _ctx.BooleanValue("CreateProduct.Data.Id2"); data.ProtocolType = _ctx.StringValue("CreateProduct.Data.ProtocolType"); data.AuthType = _ctx.StringValue("CreateProduct.Data.AuthType"); data.ProductSecret = _ctx.StringValue("CreateProduct.Data.ProductSecret"); createProductResponse.Data = data; return(createProductResponse); }
public static CreateProductResponse Unmarshall(UnmarshallerContext context) { CreateProductResponse createProductResponse = new CreateProductResponse() { HttpResponse = context.HttpResponse, RequestId = context.StringValue("CreateProduct.RequestId"), Success = context.BooleanValue("CreateProduct.Success"), ErrorMessage = context.StringValue("CreateProduct.ErrorMessage") }; CreateProductResponse.ProductInfo_ productInfo = new CreateProductResponse.ProductInfo_() { ProductKey = context.StringValue("CreateProduct.ProductInfo.ProductKey"), ProductName = context.StringValue("CreateProduct.ProductInfo.ProductName"), CatId = context.LongValue("CreateProduct.ProductInfo.CatId"), CreateUserId = context.LongValue("CreateProduct.ProductInfo.CreateUserId"), ProductDesc = context.StringValue("CreateProduct.ProductInfo.ProductDesc"), FromSource = context.StringValue("CreateProduct.ProductInfo.FromSource"), ExtProps = context.StringValue("CreateProduct.ProductInfo.ExtProps"), GmtCreate = context.StringValue("CreateProduct.ProductInfo.GmtCreate"), GmtModified = context.StringValue("CreateProduct.ProductInfo.GmtModified") }; createProductResponse.ProductInfo = productInfo; return(createProductResponse); }
public CreateProductResponse CreateProduct(CreateProductRequest request) { var result = new CreateProductResponse(); var pro = _mapper.Map <CreateProductRequest, Product>(request); pro.Id = Guid.NewGuid().ToString(); _mongoDbRepository.Create(pro); return(result); }
public CreateProductResponse SaveProduct(CreateProductRequest createProductRequest) { var product = messageMapper.MapToProduct(createProductRequest.Product); productRepository.SaveProduct(product); var createbrandresponse = new CreateProductResponse { Product = messageMapper.MapToProductDto(product) }; return(createbrandresponse); }
public NscReturn Create([FromBody] CreateProductViewModel model) { NscReturn _return = new NscReturn(); try { if (ModelState.IsValid) { NsCommerce.Product _product = new NsCommerce.Product(); _product.ProductCode = model.ProductCode; _product.ProductName = model.ProductName; _product.ShortName = model.ShortName; _product.LongName = model.LongName; _product.Details = model.Details; _product.LongDescription = model.LongDescription; _product.ShortDescription = model.ShortDescription; _product.UOMID = model.UOMID; _product.BrandID = model.BrandID; CreateProductResponse _createProductResponse = _product.Create(Utility.GetIPAddress(), Utility.GetCurrentUser().ID); _return.status = _createProductResponse.Status; if (_createProductResponse.Status == ActivityStatus.SUCCESS) { _return.returnData = new { id = _createProductResponse.ID }; } } else { _return.status = ActivityStatus.INVALID; _return.message = "Invalid data"; var validationMessage = new { validationErrors = ModelState .SelectMany(ms => ms.Value.Errors) .Select(ms => ms.ErrorMessage) }; _return.returnData = validationMessage; } } catch (Exception ex) { _return.status = ActivityStatus.EXCEPTION; _return.message = "Something went wrong"; Utility.SaveException(ex); } return(_return); }
public CreateProductResponse CreateProduct(CreateProductRequest request) { CreateProductResponse response = new CreateProductResponse(); try { Product product = request.ConvertToProduct(); productRepository.Create(product); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public CreateProductResponse SaveProduct(CreateProductRequest request) { var response = new CreateProductResponse(); WithErrorHandling(() => { var product = request.Product.MapToProduct(); _productRepository.SaveProduct(product); var productDto = product.MapToProductDto(); response.Product = productDto; response.Messages.Add("Successfully saved the product"); response.StatusCode = HttpStatusCode.Created; }, response); return(response); }
public async Task <IActionResult> Create([FromBody] CreateProductRequest productRequest) { var product = new Product { ID = Guid.NewGuid(), ProductName = productRequest.ProductName }; await _productServices.CreateProductAsync(product); var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}"; //var locationUrl = $"{baseUrl}/{ApiRoutes.Products.Get}/{product.ID}"; var locationUrl = baseUrl + "/" + ApiRoutes.Products.Get.Replace("{productID}", product.ID.ToString()); var productResponse = new CreateProductResponse { ID = product.ID }; return(Created(locationUrl, productResponse)); }
public async Task <CreateProductResponse> CreateProduct(Product product, IFormFile image) { CreateProductResponse response = new CreateProductResponse(); try { if (!image.ImageValidator()) { response.DidError = true; response.Message = "تصویر وارد شده معیوب است"; return(response); } //Save Doc Image string imgName = CodeGenerators.GenerateGUID("product_"); string path = "wwwroot/Images/Product"; string productImage = image.SaveImage(imgName, path, null); product.ProductImage = productImage; product.CreateDate = DateTime.Now; //Add Driver Doc await _context.Products.AddAsync(product); await _context.SaveChangesAsync(); response.DidError = false; response.Message = "عملیات با موفقیت انجام شد"; response.ReturnValue = product.ProductId; return(response); } catch { response.DidError = true; response.Message = "Unhandled Exception Occurred"; return(response); } }
public CreateProductResponse CreateProduct(CreateProductRequest request) { CreateProductResponse response = new CreateProductResponse(); Product product = new Product(); product.ProductName = request.ProductName; product.QuantityPerUnit = request.QuantityPerUnit; product.UnitPrice = request.UnitPrice; product.UnitsInStock = request.UnitsInStock; product.UnitsOnOrder = request.UnitsOnOrder; product.ReorderLevel = request.ReorderLevel; product.Discontinued = request.Discontinued; product.Orders = request.Orders.ConvertToOrders(); product.Category = request.Category.ConvertToCategory(); product.Supplier = request.Supplier.ConvertToSupplier(); if (product.GetBrokenRules().Count() > 0) { response.Errors = product.GetBrokenRules().ToList(); } else { try { _productRepository.Add(product); _uow.Commit(); response.Errors = new List <BusinessRule>(); } catch (Exception ex) { List <BusinessRule> errors = new List <BusinessRule>(); do { errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message)); ex = ex.InnerException; } while (ex != null); response.Errors = errors; } } return(response); }
public CreateProductResponse CreateProduct(Product product) { HttpContent content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("name", product.Name) }); content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); HttpResponseMessage response = (_client.PostAsync("https://api.stripe.com/v1/products", content)) .GetAwaiter().GetResult(); var createProductResponse = new CreateProductResponse(); if (response.IsSuccessStatusCode) { createProductResponse = JsonConvert.DeserializeObject <CreateProductResponse>(response.Content.ReadAsStringAsync().Result); } return(createProductResponse); }
public CreateProductResponse CreateProduct(CreateProductRequest request) { CreateProductResponse res = new CreateProductResponse(); string strSP = SqlCommandStore.uspCreateProduct; try { using (SqlCommand cmd = new SqlCommand(strSP)) { cmd.Parameters.Add("ProductCode", SqlDbType.NVarChar, 100).Value = request.ProductCode; cmd.Parameters.Add("ProductName", SqlDbType.VarChar, 20).Value = request.ProductName; cmd.Parameters.Add("Price", SqlDbType.Decimal, 18).Value = request.Price; cmd.Parameters.Add("CategoryID", SqlDbType.BigInt).Value = request.CategoryID; cmd.Parameters.Add("Image1Path", SqlDbType.NVarChar, 200).Value = request.Image1Path; cmd.Parameters.Add("Image2Path", SqlDbType.NVarChar, 200).Value = request.Image2Path; cmd.Parameters.Add("Image3Path", SqlDbType.NVarChar, 200).Value = request.Image3Path; cmd.Parameters.Add("Image4Path", SqlDbType.NVarChar, 200).Value = request.Image4Path; cmd.Parameters.Add("Image5Path", SqlDbType.NVarChar, 200).Value = request.Image5Path; cmd.Parameters.Add("@Return", SqlDbType.Int).Direction = ParameterDirection.ReturnValue; DataSet ds = DB.ExecuteSPDataSet(cmd); res.Code = (ReturnCode)Convert.ToInt32(cmd.Parameters["@Return"].Value); if (res.Code != ReturnCode.Success) { DB.RollBackTran(); return(res); } DB.CommitTran(); return(res); } } catch (Exception ex) { LogWriter.WriteLogException(ex); res.Code = ReturnCode.Fail; return(res); } }
public static CreateProductResponse Unmarshall(UnmarshallerContext context) { CreateProductResponse createProductResponse = new CreateProductResponse(); createProductResponse.HttpResponse = context.HttpResponse; createProductResponse.RequestId = context.StringValue("CreateProduct.RequestId"); createProductResponse.Success = context.BooleanValue("CreateProduct.Success"); createProductResponse.ErrorMessage = context.StringValue("CreateProduct.ErrorMessage"); CreateProductResponse.ProductInfo_ productInfo = new CreateProductResponse.ProductInfo_(); productInfo.ProductKey = context.StringValue("CreateProduct.ProductInfo.ProductKey"); productInfo.ProductName = context.StringValue("CreateProduct.ProductInfo.ProductName"); productInfo.CatId = context.LongValue("CreateProduct.ProductInfo.CatId"); productInfo.CreateUserId = context.LongValue("CreateProduct.ProductInfo.CreateUserId"); productInfo.ProductDesc = context.StringValue("CreateProduct.ProductInfo.ProductDesc"); productInfo.FromSource = context.StringValue("CreateProduct.ProductInfo.FromSource"); productInfo.ExtProps = context.StringValue("CreateProduct.ProductInfo.ExtProps"); productInfo.GmtCreate = context.StringValue("CreateProduct.ProductInfo.GmtCreate"); productInfo.GmtModified = context.StringValue("CreateProduct.ProductInfo.GmtModified"); createProductResponse.ProductInfo = productInfo; return createProductResponse; }
public JsonResult Create(ProductDetailView vm) { CreateProductRequest request = new CreateProductRequest(); request.ProductName = vm.ProductName; GetSupplierRequest supplierRequest = new GetSupplierRequest(); supplierRequest.SupplierID = vm.SupplierSupplierID; request.Supplier = _supplierService.GetSupplier(supplierRequest).Supplier; GetCategoryRequest categoryRequest = new GetCategoryRequest(); categoryRequest.CategoryID = vm.CategoryCategoryID; request.Category = _categoryService.GetCategory(categoryRequest).Category; request.QuantityPerUnit = vm.QuantityPerUnit; request.UnitPrice = vm.UnitPrice; request.UnitsInStock = vm.UnitsInStock; request.UnitsOnOrder = vm.UnitsOnOrder; request.ReorderLevel = vm.ReorderLevel; request.Discontinued = vm.Discontinued; CreateProductResponse response = _productService.CreateProduct(request); return(Json(response)); }
public async Task <CreateProductResponse> CreateProduct(CreateProductRequest createProductRequest) { _logger.LogInformation($"Creating a product: {JsonConvert.SerializeObject(createProductRequest)}"); Product product = new Product { DeliveryPrice = createProductRequest.DeliveryPrice, Description = createProductRequest.Description, Price = createProductRequest.Price, Name = createProductRequest.Name }; var result = await _productRepository.CreateProduct(product); var createProductResponse = new CreateProductResponse { IsSuccessful = result }; _logger.LogInformation($"Created a product with IsSuccessful: {createProductResponse.IsSuccessful}"); return(createProductResponse); }
//创建一个节点类型是网关的产品,禁止动态注册设备到产品下 public void TestCreateProduct() { CreateProductRequest request = new CreateProductRequest(); request.ProductName = "product_20190819"; request.NodeType = 1; request.AliyunCommodityCode = "iothub_senior"; request.DataFormat = 1; request.Id2 = false; request.ProtocolType = "modbus"; request.NetType = "WIFI"; request.Description = "Gateway use wifi."; request.AuthType = "id2"; DefaultAcsClient acsClient = Demo.IotClient.GetClient(); CreateProductResponse response = acsClient.GetAcsResponse(request); Console.WriteLine(response.Success); Console.WriteLine(response.ErrorMessage); CreateProductResponse.CreateProduct_Data ProductInfo = response.Data; Console.WriteLine("product name: " + ProductInfo.ProductName); Console.WriteLine("product key: " + ProductInfo.ProductKey); Console.WriteLine("product description: " + ProductInfo.Description); }
public ActionResult Edit(ProductSinglePageViewModel model, List <HttpPostedFileBase> fileUpload) { if (model.ProductViewModel.ProductId == 0) { CreateProductRequest request = new CreateProductRequest(); CreateProductResponse response = new CreateProductResponse(); request.Name = model.ProductViewModel.Name; request.Description = model.ProductViewModel.Description; request.Price = model.ProductViewModel.Price; request.Color = model.ProductViewModel.Color; request.Size = model.ProductViewModel.Size; request.BrandId = model.ProductViewModel.BrandId; request.CategoryId = model.ProductViewModel.CategoryId; request.ProductImages = new List <ProductImage>(); foreach (HttpPostedFileBase image in fileUpload) { if (image != null) { ProductImage productImeage = new ProductImage(); productImeage.ImageMimeType = image.ContentType; productImeage.ImageData = new byte[image.ContentLength]; image.InputStream.Read(productImeage.ImageData, 0, image.ContentLength); // First image add for displaying in product list page if (request.ProductImage == null) { request.ProductImage = new ProductImage(); request.ProductImage = productImeage; } // Other images add to list request.ProductImages.Add(productImeage); } } response = productService.CreateProduct(request); if (response.Success) { return(RedirectToAction("Index")); } else { model.Success = false; model.ErrorMessage = response.Message; return(View(model)); } } else { UpdateProductRequest request = new UpdateProductRequest(); UpdateProductResponse response = new UpdateProductResponse(); request.ProductId = model.ProductViewModel.ProductId; request.Name = model.ProductViewModel.Name; request.Description = model.ProductViewModel.Description; request.Price = model.ProductViewModel.Price; request.Color = model.ProductViewModel.Color; request.Size = model.ProductViewModel.Size; request.BrandId = model.ProductViewModel.BrandId; request.CategoryId = model.ProductViewModel.CategoryId; request.ProductImages = new List <ProductImage>(); foreach (HttpPostedFileBase image in fileUpload) { if (image != null) { ProductImage productImeage = new ProductImage(); productImeage.ImageMimeType = image.ContentType; productImeage.ImageData = new byte[image.ContentLength]; image.InputStream.Read(productImeage.ImageData, 0, image.ContentLength); // First image add for displaying in product list page if (request.ProductImage == null) { request.ProductImage = new ProductImage(); request.ProductImage = productImeage; } // Other images add to list request.ProductImages.Add(productImeage); } } response = productService.UpdateProduct(request); if (response.Success) { return(RedirectToAction("Index")); } else { model.Success = false; model.ErrorMessage = response.Message; return(View(model)); } } }