public ActionResult Create([Bind(Include = "Id,Text,Price,Date,Category")] Menu menu) { if (ModelState.IsValid) { db.Menus.Add(menu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(menu)); }
public ActionResult Edit([Bind(Include = "Id,Text,Price,Date,Category")] Menu menu) { if (ModelState.IsValid) { db.Entry(menu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(menu)); }
public ActionResult Delete(int?id) { MenuDB db = new MenuDB(); Menu menu = db.Menus.Find(id); db.Menus.Remove(menu); db.SaveChanges(); ViewBag.Info = string.Format( "Menu item deleted: {0}", menu.Id); return(View("Index", db.Menus.ToList())); }
public ActionResult CreateMenu(Menu m) { MenuDB db = new MenuDB(); m.Date = DateTime.Now; db.Menus.Add(m); db.SaveChanges(); if (ModelState.IsValid) { ViewBag.Info = string.Format( "Menu created: {0}, Price: {1}, Category {2}", m.Text, m.Price, m.Category); } else { ViewBag.Info = "not valid"; } return(View("Index", db.Menus.ToList())); }