public ActionResult Create(MenuItem item) { _context.MenuItems.Add(item); _context.SaveChanges(); return(RedirectToAction("Items", new { isAdmin = true })); }
public ActionResult Create(MenuItem model) { if (ModelState.IsValid) { db.MenuItems.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Invalid Operation"); return(View()); } }
public ActionResult Add(int id) { // if cart for User(1) is empty if (_context.Cart.FirstOrDefault(c => c.UserId == 1) == null) { _context.Cart.Add(new Cart() { UserId = 1 }); _context.SaveChanges(); } // else go on!!!!! var item = _context.MenuItems.Find(id); item.CartId = _context.Cart.FirstOrDefault(c => c.UserId == 1).Id; _context.SaveChanges(); return(RedirectToAction("Index")); }