public async Task <IActionResult> Edit(int id, [Bind("Id,Name,IdCategory,Price,Created")] Product product) { try { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { await productComponent.Edit(product); return(RedirectToAction("Index")); } } catch (Exception ex) { //Log the error ModelState.AddModelError("", ex.Message); } var categories = await categoryComponent.GetAllCategories(); if (categories == null) { RedirectToAction("Index"); } ViewBag.CategoryList = new SelectList(categories, "Id", "Name"); return(View(product)); }
public async Task <IActionResult> EditProduct(int id, [FromBody] Product product) { if (product == null || id <= 0) { return(BadRequest()); } var oldProduct = await productComponent.GetProduct(id); if (oldProduct == null) { return(NotFound()); } product.Id = id; await productComponent.Edit(product); return(Json("Produto alterado com sucesso!")); }