public IHttpActionResult PutProduct(int id, ProductUpdateRequestModel requestModel) { Product product = _ctx.Products.FirstOrDefault(x => x.Id == id); if (product == null) { return(NotFound()); } product.Name = requestModel.Name; try { _ctx.Entry(product).State = EntityState.Modified; _ctx.SaveChanges(); } catch (Exception ex) { throw; } return(Content(HttpStatusCode.OK, new ProductDto { Id = product.Id, StoreId = product.StoreId, Name = product.Name })); }
public async Task <IActionResult> Edit(int productId, [Bind("Code,Name,Photo,Price")] ProductUpdateRequestModel productUpdateRequestModel) { if (ModelState.IsValid) { await _productCatalogService.UpdateProduct(productId, productUpdateRequestModel); } return(RedirectToAction("Index")); }
/// <summary> /// Update product in database /// </summary> /// <param name="productUpdateRequestModel"></param> /// <returns></returns> public async Task UpdateProduct(int productId, ProductUpdateRequestModel productUpdateRequestModel) { var content = new StringContent(JsonConvert.SerializeObject(productUpdateRequestModel), Encoding.UTF8, "application/json"); var updateResponse = await _httpClient.PutAsync($"{Endpoint}/{productId}", content); if (!updateResponse.IsSuccessStatusCode) { throw new Exception("Product couldn't be updated."); } }
public IHttpActionResult PutProduct(int id, ProductUpdateRequestModel requestModel) { Product product = _ctx.Products.FirstOrDefault(x => x.Id == id); if (product == null) { return NotFound(); } product.Name = requestModel.Name; try { _ctx.Entry(product).State = EntityState.Modified; _ctx.SaveChanges(); } catch (Exception ex) { throw; } return Content(HttpStatusCode.OK, new ProductDto { Id = product.Id, StoreId = product.StoreId, Name = product.Name }); }
public ProductUpdateServiceRequest(int productId, ProductUpdateRequestModel model) { ProductId = productId; Model = model; }
public async Task <IActionResult> Update([FromRoute] int productId, [FromBody] ProductUpdateRequestModel model) { var response = await _mediator.Send(new ProductUpdateServiceRequest(productId, model)); return(Ok(response)); }