Exemplo n.º 1
0
        public static void AddToCart(BookedFoodViewModel model, ref CartViewModel cart)
        {
            var item = cart.Foods.FirstOrDefault(t => t.ID == model.ID);

            if (item != null)
            {
                cart.Foods[cart.Foods.IndexOf(item)].Quantity += model.Quantity;
            }
            else
            {
                cart.Foods.Add(model);
            }
        }
Exemplo n.º 2
0
        // GET: GioHang
        public ActionResult AddToCart(BookedFoodViewModel model)
        {
            CartViewModel cart;

            if (Session[ConstantsVariable.CART] != null)
            {
                cart = (CartViewModel)Session[ConstantsVariable.CART];
                CartQueries.AddToCart(model, ref cart);
            }
            else
            {
                cart = new CartViewModel();
                cart.Foods.Add(model);
            }
            Session[ConstantsVariable.CART] = cart;
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 3
0
        public static List <BookedFoodViewModel> GetChoosingFoods(CartViewModel cart)
        {
            QUANLYQUANANEntities entities = new QUANLYQUANANEntities();
            var foods = entities.MONANs.Select(t => t.MAMONAN).ToList().OrderBy(t => t);
            List <BookedFoodViewModel> res = new List <BookedFoodViewModel>();
            BookedFoodViewModel        food;

            if (cart == null)
            {
                foreach (var item in foods)
                {
                    food = new BookedFoodViewModel()
                    {
                        ID = item, Quantity = 0
                    };
                    res.Add(food);
                }
            }
            else
            {
                foreach (var item in foods)
                {
                    var choosenFood = cart.Foods.FirstOrDefault(t => t.ID == item);
                    if (choosenFood != null)
                    {
                        food = new BookedFoodViewModel()
                        {
                            ID = item, Quantity = choosenFood.Quantity
                        };
                    }
                    else
                    {
                        food = new BookedFoodViewModel()
                        {
                            ID = item, Quantity = 0
                        };
                    }
                    res.Add(food);
                }
            }
            return(res);
        }