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

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

            return(Ok(burger));
        }
Example #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));
        }
Example #3
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());
        }
Example #4
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"));
        }