public JsonResult Post([FromBody] Product product) { try { if (ModelState.IsValid) { var newProduct = Mapper.Map <Product>(product); _repository.AddProduct(newProduct); if (_repository.SaveAll()) { Response.StatusCode = (int)HttpStatusCode.Created; return(Json(Mapper.Map <Product>(newProduct))); } } } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Message = ex.Message })); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Message = "Failed", ModelState = ModelState })); }
public IActionResult DeleteConfirmed(int id) { _logger.Log(_userManager.GetUserId(HttpContext.User), "DeleteProductsConfirmed"); _repository.DeleteProduct(id); _repository.SaveAll(); return(RedirectToAction("Products")); }