[ValidateAntiForgeryToken] // Checking the token from our resources public ActionResult EditProductCateogry(int?productID, int?categoryId, ProductCategoryViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Index", "Home")); } // Looking for a product to update. var productToUpdate = _db.Products.Find(productID); productToUpdate.Price = model.Product.Price; productToUpdate.ProductCode = model.Product.ProductCode; // Updating the related product on the db _db.SaveChanges(); // Updating the Category type on ProductInCategories var prodInCat = _db.ProductInCategories.Where(pc => pc.ProductID == productID).FirstOrDefault(); prodInCat.CategoryID = (int)categoryId; // Updating the related product on the db _db.SaveChanges(); return(RedirectToAction(nameof(EditProductCateogry), new { productID = productID, messageType = 1 })); }// end -> HttpPost
[ValidateAntiForgeryToken] // Checking the token from our resources public ActionResult EditProduct(int?Id, Product product) { if (!ModelState.IsValid) { return(RedirectToAction("Index", "Home")); } // Looking for a product to update. var productToUpdate = _db.Products.Find(Id); productToUpdate.Price = product.Price; productToUpdate.ProductCode = product.ProductCode; // Updating the related product on the db _db.SaveChanges(); return(RedirectToAction(nameof(EditProduct), new { productID = Id, messageType = 1 })); }// end -> HttpPost