Ejemplo n.º 1
0
        public async Task <ActionResult> AddToCartDrinkFromCart(int?DrinkId, int Quantity)
        {
            var drink = await DrinkServices.FindDrinkAsync(DrinkId);

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

            //Find if the drink exists in the CartDrink list
            var existingDrink = cart.CartDrinks.FirstOrDefault(x => x.DrinkId == drink.Id);

            //If it does,add 1 to its quantity
            if (existingDrink != null)
            {
                existingDrink.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"));
        }
Ejemplo n.º 2
0
        //DRINK
        public async Task <ActionResult> AddToCartDrink(int?DrinkId)
        {
            var drink = await DrinkServices.FindDrinkAsync(DrinkId);

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

            //Find if the drink exists in the CartDrink list
            var existingDrink = cart.CartDrinks.FirstOrDefault(x => x.DrinkId == drink.Id);

            //If it does,add 1 to its quantity
            if (existingDrink != null)
            {
                existingDrink.Quantity++;
                Session["count"] = Convert.ToInt32(Session["count"]) + 1;
            }
            //If it doesnt,create a new CartDrink and save it into the CartDrinks list of the cart
            else
            {
                cart.CartDrinks.Add(new CartDrink()
                {
                    DrinkId  = drink.Id,
                    Name     = drink.Name,
                    Litre    = drink.Litre,
                    Price    = drink.Price,
                    Quantity = 1
                });
                Session["count"] = Convert.ToInt32(Session["count"]) + 1;
            }

            SaveCart(cart);

            return(new EmptyResult());
        }
Ejemplo n.º 3
0
        // GET: Drink/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(View("Error"));
            }
            Drink drink = await DrinkServices.FindDrinkAsync(id);

            if (drink == null)
            {
                return(View("Error"));
            }
            return(View(drink));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Name,Litre,Price")] Drink drink, HttpPostedFileBase ImageUrl)
        {
            if (ModelState.IsValid)
            {
                //Get the photo
                if (ImageUrl != null)
                {
                    ImageUrl.SaveAs(Server.MapPath("~/Content/DrinkImages/" + ImageUrl.FileName));
                    drink.ImageUrl = ImageUrl.FileName;
                }


                await DrinkServices.AddDrinkAsync(drink);

                return(RedirectToAction("Index"));
            }

            return(View(drink));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> DeleteDrink(int DrinkId)
        {
            var drink = await DrinkServices.FindDrinkAsync(DrinkId);

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

            //Find if the drink exists in the CartDrinks list and find its Quantity
            var existingItem    = cart.CartDrinks.FirstOrDefault(x => x.DrinkId == drink.Id);
            var quantityDeleted = existingItem.Quantity;

            //If it does,remove it from the list
            if (existingItem != null)
            {
                cart.CartDrinks.Remove(existingItem);
            }
            Session["count"] = Convert.ToInt32(Session["count"]) - quantityDeleted;

            SaveCart(cart);

            return(RedirectToAction("Index", "Cart"));
        }
Ejemplo n.º 7
0
 // GET: Drink
 public async Task <ActionResult> Index()
 {
     return(View(await DrinkServices.GetDrinksAsync()));
 }
Ejemplo n.º 8
0
 public DrinkController(DrinkServices drinkServ)
 {
     _drinkServ = drinkServ;
 }