コード例 #1
0
        public IActionResult AddDrinkToOrder([Bind("ID,Type,DrinkSize")] Drink drink)
        {
            if (UserID != 0)
            {
                if (drink.ID == 0)
                {
                    Drink temp = _context.ItemDB.Where(i => i.GetType() == typeof(Drink)).Cast <Drink>().FirstOrDefault(s => s.Type == drink.Type);
                    if (temp == null)
                    {
                        return(RedirectToAction("Index", "Menus"));
                    }
                    drink.ID       = Helpers.Utilities.GenerateGuid();
                    drink.Name     = temp.Name;
                    drink.PrepTime = temp.PrepTime;
                    drink.Price    = temp.Price;
                    drink.AddDrinkToSpcInst();
                }
                else
                {
                    Drink temp = _context.ItemDB.Where(i => i.GetType() == typeof(Drink)).Cast <Drink>().FirstOrDefault(x => x.ID == drink.ID);
                    if (temp == null)
                    {
                        return(RedirectToAction("Index", "Menus"));
                    }
                    drink.ID       = Helpers.Utilities.GenerateGuid();
                    drink.Name     = temp.Name;
                    drink.PrepTime = temp.PrepTime;
                    drink.Price    = temp.Price;
                    drink.AddDrinkToSpcInst();
                }

                _context.UserDB.FirstOrDefault(u => u.ID == UserID).ActiveOrder.Items.Add(drink);
                _context.SaveDatabase(_context.UserDB);

                return(RedirectToAction("Index", "Menus"));
            }

            return(RedirectToAction("Logout", "Account"));
        }