Esempio n. 1
0
 public IActionResult Edit(Product product)
 {
     _logger.Log(_userManager.GetUserId(HttpContext.User), "EditProduct");
     if (ModelState.IsValid)
     {
         _repository.UpdateProduct(product);
         _repository.SaveAll();
         return(RedirectToAction("Products"));
     }
     return(View(product));
 }
Esempio n. 2
0
        public JsonResult Update([FromBody] Product product)
        {
            if (ModelState.IsValid)
            {
                var productToUpdate = Mapper.Map <Product>(product);
                _repository.UpdateProduct(product);
                if (_repository.SaveAll())
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return(Json(Mapper.Map <Product>(productToUpdate)));
                }
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { Message = "Failed to update" }));
        }