public async Task <IHttpActionResult> GetBurger(int?id)
        {
            Burger burger = await BurgerServices.FindBurgerAsync(id);

            if (burger == null)
            {
                return(NotFound());
            }

            return(Ok(burger));
        }
Beispiel #2
0
        // GET: Burger/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(View("Error"));
            }
            Burger burger = await BurgerServices.FindBurgerAsync(id);

            if (burger == null)
            {
                return(View("Error"));
            }
            return(View(burger));
        }
        public async Task <ActionResult> Menu()
        {
            ViewBag.BreadId  = new SelectList(db.Breads, "Id", "NamePrice");
            ViewBag.CheeseId = new SelectList(db.Cheeses, "Id", "NamePrice");
            ViewBag.MeatId   = new SelectList(db.Meats, "Id", "NamePrice");
            ViewBag.SauceId  = new SelectList(db.Sauces, "Id", "NamePrice");
            ViewBag.VeggieId = new SelectList(db.Veggies, "Id", "NamePrice");


            var model = new BurgerDrinkViewModel
            {
                Burgers = await BurgerServices.GetBurgersAsync(),
                Drinks  = await DrinkServices.GetDrinksAsync()
            };

            return(View(model));
        }
Beispiel #4
0
        public async Task <ActionResult> AddToCartBurger(int?BurgerId)
        {
            //To build later
            if (BurgerId == null)
            {
                return(View("Error"));
            }


            var burger = await BurgerServices.FindBurgerAsync(BurgerId);

            //Create the cart if it doesnt exist or get the existing cart
            var cart = CreateOrGetCart();

            //Find if the burger exists in the CartBurger list
            var existingBurger = cart.CartBurgers.FirstOrDefault(x => x.BurgerId == burger.Id);

            //If it does,add 1 to its quantity
            if (existingBurger != null)
            {
                existingBurger.Quantity++;
                Session["count"] = Convert.ToInt32(Session["count"]) + 1;
            }
            //If it doesnt,create a new CartBurger and save it into the CartBurgers list of the cart
            else
            {
                cart.CartBurgers.Add(new CartBurger()
                {
                    BurgerId   = burger.Id,
                    Name       = burger.Name,
                    Price      = burger.Price,
                    Quantity   = 1,
                    MeatName   = burger.Meat.Name,
                    BreadName  = burger.Bread.Name,
                    CheeseName = burger.Cheese.Name,
                    SauceName  = burger.Sauce.Name,
                    VeggieName = burger.Veggie.Name
                });
                Session["count"] = Convert.ToInt32(Session["count"]) + 1;
            }

            SaveCart(cart);
            return(new EmptyResult());
        }
Beispiel #5
0
        public async Task <ActionResult> AddToCartBurgerFromCart(int?BurgerId, int Quantity)
        {
            //To build later
            if (BurgerId == null)
            {
                return(View("Error"));
            }


            var burger = await BurgerServices.FindBurgerAsync(BurgerId);

            //Create the cart if it doesnt exist or get the existing cart
            var cart = CreateOrGetCart();

            //Find if the burger exists in the CartBurger list
            var existingBurger = cart.CartBurgers.FirstOrDefault(x => x.BurgerId == burger.Id);


            if (existingBurger != null)
            {
                existingBurger.Quantity = Quantity;
                var cartburgersCount  = 0;
                var cartdrinksCount   = 0;
                var cartBurgersLength = cart.CartBurgers.Count;
                var cartDrinksLength  = cart.CartDrinks.Count;
                for (int i = 0; i < cartBurgersLength; i++)
                {
                    cartburgersCount += cart.CartBurgers[i].Quantity;
                }

                for (int i = 0; i < cartDrinksLength; i++)
                {
                    cartdrinksCount += cart.CartDrinks[i].Quantity;
                }

                Session["count"] = cartburgersCount + cartdrinksCount;
            }

            SaveCart(cart);
            return(RedirectToAction("Index", "Cart"));
        }
 // GET: api/BurgerApi
 public async Task <List <Burger> > GetBurgers()
 {
     return(await BurgerServices.GetBurgersAsync());
 }
Beispiel #7
0
 // GET: Burger
 public async Task <ActionResult> Index()
 {
     return(View(await BurgerServices.GetBurgersAsync()));
 }