public bool Delete(Food food) { Food entity = db.Foods.Find(food.Id); db.Foods.Remove(entity); db.SaveChanges(); return true; }
public ActionResult Delete(Food food) { try { // TODO: Add delete logic here bool deleted = service.Delete(food); if (deleted) { return RedirectToAction("Index"); } return View(food); } catch { return View(); } }
public ActionResult Create(Food food) { try { // TODO: Add insert logic here bool saved = service.Save(food); if (saved) { return RedirectToAction("Index"); } return View(food); } catch { return View(food); } }
public ActionResult Edit(Food food) { try { // TODO: Add update logic here bool updated = service.Update(food); if (updated) { return RedirectToAction("Index"); } return View(food); } catch { return View(); } }
public ViewFood(Food food) { Id = food.Id; Name = food.Name; Price = food.Price; }
public bool Update(Food food) { db.Entry(food).State = EntityState.Modified; db.SaveChanges(); return true; }
public bool Save(Food food) { db.Foods.Add(food); db.SaveChanges(); return true; }