コード例 #1
0
        public ActionResult Edit(int id, MenuItemModels collection)
        {
            try
            {
                // TODO: Add update logic here

                using (db = new ApplicationDbContext())
                {
                    var r = db.MenuItems.Find(id);
                    collection.ApplicationUserId   = User.Identity.GetUserId();
                    collection.MenuModels_id       = r.MenuModels_id;
                    collection.RestaurantModels_id = r.RestaurantModels_id;
                    db.Entry(r).CurrentValues.SetValues(collection);
                    db.SaveChanges();

                    TempData["Message"] = $"You have edited restaurant: {r.Name}";

                    return(RedirectToAction("Index", new { Id = collection.MenuModels_id }));
                }
            }
            catch (Exception e)
            {
                return(Content(e.ToString()));
            }
        }
コード例 #2
0
        public ActionResult Create(MenuItemModels collection)
        {
            try
            {
                // TODO: Add insert logic here

                using (db = new ApplicationDbContext())
                {
                    MenuItemModels menu = new MenuItemModels {
                        Name = collection.Name,
                        Desc = collection.Desc, Price = collection.Price, MenuModels_id = collection.MenuModels_id
                    };
                    menu.ApplicationUserId   = User.Identity.GetUserId();
                    menu.MenuModels_id       = collection.MenuModels_id;
                    menu.RestaurantModels_id = db.Menus.Find(collection.MenuModels_id).RestaurantModels_id;
                    db.MenuItems.Add(menu);
                    db.SaveChanges();

                    TempData["Message"] = $"You have created a menu item: {menu.Name}";

                    return(RedirectToAction("Index", new { Id = collection.MenuModels_id }));
                }
            }
            catch (Exception e)
            {
                return(Content(e.Message));
            }
        }
コード例 #3
0
ファイル: MenuEntity.cs プロジェクト: JosephG3001/TheBox
 public void AddMenuItemModelRange(List <MenuItemModel> menuItemModels)
 {
     menuItemModels.First().IsSelected = true;
     foreach (var item in menuItemModels)
     {
         MenuItemModels.Add(item);
     }
     RecalculateVariables();
 }
コード例 #4
0
        // GET: MenuItem/Edit/5
        public ActionResult Edit(int id)
        {
            var menu = new MenuItemModels();

            using (db = new ApplicationDbContext())
            {
                menu = db.MenuItems.Find(id);
            }
            return(View(menu));
        }
コード例 #5
0
        public ActionResult Buy(int itemId)
        {
            MenuItemModels        item = db.MenuItems.Find(itemId);
            List <MenuItemModels> x    = (List <MenuItemModels>)Session[User.Identity.GetUserId()];

            x.Add(item);
            Session[User.Identity.GetUserId()] = x;
            TempData["Message"] = $"You added item: {item.Name} to cart";
            return(RedirectToAction("AllMenuItems", new { menuId = item.MenuModels_id }));
            //return View("AllMenuItems", db.MenuItems.Where(mit => mit.MenuModels_id == item.MenuModels_id).ToList());
        }
コード例 #6
0
ファイル: MenuEntity.cs プロジェクト: JosephG3001/TheBox
 /// <summary>
 /// Gets the visible menu items.  Takes 11 items from the main list of menuItems.
 /// </summary>
 /// <returns></returns>
 public List <MenuItemModel> GetVisibleMenuItems()
 {
     return(MenuItemModels.Skip(PageIndex * MaxMenuLabels).Take(MaxMenuLabels).ToList());
 }