public ViewResult Edit(int productId) { SportNutrition product = repository.Products .FirstOrDefault(p => p.SportNutritionId == productId); return(View(product)); }
public RedirectToRouteResult RemoveFromCart(Cart cart, int nutritionId, string returnUrl) { SportNutrition product = repository.Products .FirstOrDefault(p => p.SportNutritionId == nutritionId); if (product != null) { cart.RemoveLine(product); } return(RedirectToAction("Index", new { returnUrl })); }
public ActionResult Delete(int productId) { SportNutrition deletedProduct = repository.DeleteProduct(productId); if (deletedProduct != null) { TempData["message"] = string.Format("{0} was deleted", deletedProduct.Name); } return(RedirectToAction("Index")); }
public SportNutrition DeleteProduct(int productID) { SportNutrition dbEntry = context.Products.Find(productID); if (dbEntry != null) { context.Products.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public ActionResult Edit(SportNutrition product, HttpPostedFileBase image) { if (ModelState.IsValid) { repository.SaveProduct(product); TempData["message"] = string.Format("{0} has been saved", product.Name); return(RedirectToAction("Index")); } else { // there is something wrong with the data values return(View(product)); } }
public void SaveProduct(SportNutrition product) { if (product.SportNutritionId == 0) { context.Products.Add(product); } else { SportNutrition dbEntry = context.Products.Find(product.SportNutritionId); if (dbEntry != null) { dbEntry.Name = product.Name; dbEntry.Description = product.Description; dbEntry.Price = product.Price; dbEntry.Category = product.Category; dbEntry.ImageName = product.ImageName; } } context.SaveChanges(); }
public void SaveProduct(SportNutrition product) { throw new NotImplementedException(); }