public async Task <UpdateProductResponse> UpdateProduct(Guid id, UpdateProductRequest updateProductRequest) { _logger.LogInformation($"Updating product with id: {id}"); var product = await _productRepository.GetProductById(id); if (product == null) { _logger.LogInformation($"Could not find product with id: {id}"); return(new UpdateProductResponse { IsSuccessful = false }); } product.Name = updateProductRequest.Name; product.Description = updateProductRequest.Description; product.Price = updateProductRequest.Price; product.DeliveryPrice = updateProductRequest.DeliveryPrice; var result = await _productRepository.UpdateProduct(product); var updateProductResponse = new UpdateProductResponse { IsSuccessful = result }; _logger.LogInformation($"Updated a product with IsSuccessful: {updateProductResponse.IsSuccessful}"); return(updateProductResponse); }
//根据产品PK更新产品信息,如产品名称和产品描述 private static void TestUpdateProduct() { IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>"); DefaultAcsClient client = new DefaultAcsClient(clientProfile); UpdateProductRequest request = new UpdateProductRequest(); //更新的产品来源于CreateProductResponse request.ProductKey = "<productKey>"; request.ProductName = "<productName>"; request.ProductDesc = "<productDesc>"; try { UpdateProductResponse response = client.GetAcsResponse(request); Console.WriteLine(response.Success); Console.WriteLine(response.ErrorMessage); } catch (ServerException e) { Console.WriteLine(e.ErrorCode); Console.WriteLine(e.ErrorMessage); } catch (ClientException e) { Console.WriteLine(e.ErrorCode); Console.WriteLine(e.ErrorMessage); } Console.ReadKey(); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { UpdateProductResponse response = new UpdateProductResponse(); 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("Tags", targetDepth)) { var unmarshaller = new ListUnmarshaller <Tag, TagUnmarshaller>(TagUnmarshaller.Instance); response.Tags = unmarshaller.Unmarshall(context); continue; } } return(response); }
public UpdateProductResponse UpdateProduct(UpdateProductRequest request) { var response = new UpdateProductResponse { Errors = new List <Error>() }; try { Repository.UpdateProduct(request.ProductEntity); response.Message = "Product updated successfully!"; } catch (Exception ex) { response.Errors.Add( new Error { CustomisedMessage = "Unable to update product", StackTrace = ex.StackTrace, SystemMessage = ex.Message, }); Logger.Fatal(request); Logger.Fatal(response, ex); } return(response); }
public async Task <IActionResult> OnPostAsync() { ProductResponse = await _productApiController.CreateProduct(ProductRequest); ProductRequest = _mapper.Map <UpdateProductRequest>(ProductResponse); return(this.RedirectToPage("/Admin/Products/Index")); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateProductRequest request) { request.Product.Id = id; UpdateProductResponse result = await _ProductAppService.updateProduct(request); if (result.Success) { return(Ok(result)); } return(NotFound(result)); }
public static UpdateProductResponse Unmarshall(UnmarshallerContext context) { UpdateProductResponse updateProductResponse = new UpdateProductResponse(); updateProductResponse.HttpResponse = context.HttpResponse; updateProductResponse.RequestId = context.StringValue("UpdateProduct.RequestId"); updateProductResponse.Success = context.BooleanValue("UpdateProduct.Success"); updateProductResponse.ErrorMessage = context.StringValue("UpdateProduct.ErrorMessage"); return(updateProductResponse); }
public async Task Should_Verify_Item_Update_Test() //product update within in-memory-db or combined //Arrange { AlzaDbContext inMemoryDbContext = _factory.Create(); bool isDbReady = await inMemoryDbContext.Database.EnsureCreatedAsync(); isDbReady.ShouldBeTrue(); try { _factory.SeedTestingData(inMemoryDbContext); } catch (Exception e) { e.ShouldBeNull(); } var sut = new UpdateProductRequest.Handler(_mockMapper.Object, inMemoryDbContext); //Act UpdateProductResponse result = await sut.Handle(new UpdateProductRequest { ProductId = Guid.Empty }, CancellationToken.None); //Assert result.ProductUpdated.ShouldBe(false); result.ProductDescription.ShouldBeNull(); result.ProductUpdateMessage.ShouldBe("Product not found"); _mockMapper.Verify(mapper => mapper.Map <UpdateProductResponse>(It.IsAny <UpdateProductRequest>()), Times.Never); //Act result = await sut.Handle(new UpdateProductRequest { ProductId = Guid.Parse("1BBDFAD4-B8CD-472A-881B-08D890B3E94F"), Description = "Old description" }, CancellationToken.None); //Assert result.ProductUpdated.ShouldBe(false); result.ProductDescription.ShouldBeNull(); result.ProductUpdateMessage.ShouldBe("Product already up to date"); _mockMapper.Verify(mapper => mapper.Map <UpdateProductResponse>(It.IsAny <UpdateProductRequest>()), Times.Never); Product dbResult = await inMemoryDbContext.Products.FindAsync(Guid.Parse("1BBDFAD4-B8CD-472A-881B-08D890B3E94F")); dbResult.Description.ShouldBe("Old description"); //Act _ = await sut.Handle(new UpdateProductRequest { ProductId = Guid.Parse("1BBDFAD4-B8CD-472A-881B-08D890B3E94F"), Description = "New description" }, CancellationToken.None); //Assert dbResult = await inMemoryDbContext.Products.FindAsync(Guid.Parse("1BBDFAD4-B8CD-472A-881B-08D890B3E94F")); dbResult.Description.ShouldBe("New description"); _mockMapper.Verify(mapper => mapper.Map <UpdateProductResponse>(It.IsAny <Product>()), Times.Once); await inMemoryDbContext.Database.EnsureDeletedAsync(); await inMemoryDbContext.DisposeAsync(); }
/// <summary> /// Updates the product. --by Will /// </summary> /// <param name="productBE">The product BE.</param> /// <returns></returns> public bool UpdateProduct(ProductBE productBE) { UpdateProductRequest request = new UpdateProductRequest(); request.product = productBE; UpdateProductResponse response = MyChannelFactory.CreateChannel().UpdateProduct(request); if (response.IsFailed) { throw (new Exception(response.Message)); } return(!response.IsFailed); }
public UpdateProductResponse EditProduct(UpdateProductRequest updateProductRequest) { UpdateProductResponse updateProductResponse = null; if (updateProductRequest.Id == updateProductRequest.Id) { var product = _messageMapper.MapToProduct(updateProductRequest.product); _productRepository.EditProduct(product); _messageMapper.MapToProductDto(product); return(new UpdateProductResponse { }); } return(updateProductResponse); }
public UpdateProductResponse EditProduct(UpdateProductRequest request) { var response = new UpdateProductResponse(); WithErrorHandling(() => { var product = request.Product.MapToProduct(); _productRepository.UpdateProduct(product); response.Messages.Add("Successfully updated the product"); response.StatusCode = HttpStatusCode.OK; }, response); return(response); }
/// <summary> /// Updates the product. --by Will /// </summary> /// <param name="productBE">The product BE.</param> /// <returns></returns> public bool UpdateProduct(ProductBE productBE) { UpdateProductRequest request = new UpdateProductRequest(); request.product = productBE; UpdateProductResponse response = MyChannelFactory.CreateChannel().UpdateProduct(request); if (response.IsFailed) { ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); log.Error("error", new Exception(response.Message)); log.Fatal("fatal", new Exception(response.Message)); throw (new Exception(response.Message)); } return(!response.IsFailed); }
public UpdateProductResponse EditProduct(UpdateProductRequest updateProductRequest) { UpdateProductResponse updateProductResponse = null; var product = messageMapper.MapToProduct(updateProductRequest.Product); productRepository.EditProduct(product); var brandDto = messageMapper.MapToProductDto(product); updateProductResponse = new UpdateProductResponse { }; return(updateProductResponse); }
public UpdateProductResponse UpdateProduct(UpdateProductRequest request) { UpdateProductResponse response = new UpdateProductResponse(); try { Product product = request.ConvertToProduct(); productRepository.Update(product); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
//根据产品PK更新产品信息,如产品名称和产品描述 public void TestUpdateProduct() { DefaultAcsClient acsclient = Demo.IotClient.GetClient(); UpdateProductRequest request = new UpdateProductRequest(); //更新的产品来源于CreateProduct request.ProductKey = "<productKey>"; request.ProductName = "csharp_ide"; request.Description = "package manage"; UpdateProductResponse response = acsclient.GetAcsResponse(request); Console.WriteLine(response.Success); Console.WriteLine(response.ErrorMessage); Console.WriteLine(response.Code); }
/// <summary> /// Updates the product. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public UpdateProductResponse UpdateProduct(UpdateProductRequest request) { UpdateProductResponse response = new UpdateProductResponse(); ProductService service = new ProductService(); try { bool result = service.Update(request.product); if (result == false) { response.IsFailed = true; response.Message = "Update Product failed."; } } catch (Exception ex) { response.IsFailed = true; response.Message = ex.Message; } return(response); }
public UpdateProductResponse UpdateProduct(UpdateProductRequest request) { UpdateProductResponse res = new UpdateProductResponse(); string strSP = SqlCommandStore.uspUpdateProduct; try { using (SqlCommand cmd = new SqlCommand(strSP)) { cmd.Parameters.Add("ProductID", SqlDbType.BigInt).Value = request.ProductID; cmd.Parameters.Add("ProductCode", SqlDbType.VarChar, 200).Value = request.ProductCode; cmd.Parameters.Add("ProductName", SqlDbType.NVarChar, 100).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; 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.Success; return(res); } }
public Task <UpdateProductResponse> updateProduct(UpdateProductRequest request) { UpdateProductCommand command = new UpdateProductCommand ( request.Product.Id, request.Product.Name, request.Product.Note, request.Product.Code, request.Product.OtherUnitOfProduct, request.Product.UnitId, request.Product.WeightPerUnit, request.Product.Preservation.ID ); Task <object> product = (Task <object>)Bus.SendCommand(command); UpdateProductResponse response = new UpdateProductResponse(); response = Common <UpdateProductResponse> .checkHasNotification(_notifications, response); if (response.Success) { response.Data = (bool)product.Result; } return(Task.FromResult(response)); }
public UpdateProductResponse UpdateProduct(UpdateProductRequest request) { UpdateProductResponse response = new UpdateProductResponse(); try { Product productToUpdate = productsRepository.Find(request.Product.Id); productToUpdate.Name = request.Product.Name; productToUpdate.Description = request.Product.Description; productsRepository.Save(productToUpdate); unitOfWork.Commit(); response.Status = true; response.Message = "ok"; } catch (Exception e) { response.Status = false; response.Message = e.Message; if (e.InnerException != null) { response.Message += Environment.NewLine; response.Message += string.Format("Inner exception: {0}", e.InnerException.Message); } } return response; }
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)); } } }