public ActionResult MiniShoppingCartSingleItem(int id)
        {
            DishesBuss buss     = new DishesBuss();
            var        dishInfo = buss.GetSingleDishes(id);

            return(View(dishInfo));
        }
        public ActionResult DishList(int id)
        {
            DishesBuss buss   = new DishesBuss();
            var        dishes = buss.GetDishes(id);

            return(View(dishes));
        }
        private List <ShoppingCartItem> GetShoppingCartInfoFromCookie()
        {
            List <ShoppingCartItem> shoppingCartItems = new List <ShoppingCartItem>();
            var jser = new JavaScriptSerializer();

            if (Request.Cookies["shoppingCart"] != null)
            {
                var cookieJson = Request.Cookies["shoppingCart"].Value;
                shoppingCartItems = jser.Deserialize <List <ShoppingCartItem> >(cookieJson);

                if (shoppingCartItems != null && shoppingCartItems.Count > 0)
                {
                    int[] ids = shoppingCartItems.Select(p => p.ItemID).ToArray();

                    DishesBuss buss    = new DishesBuss();
                    var        details = buss.GetDishesByIds(ids);

                    foreach (var item in shoppingCartItems)
                    {
                        foreach (var detailItem in details)
                        {
                            if (item.ItemID == detailItem.Id)
                            {
                                item.OName = detailItem.OtherName;
                                break;
                            }
                        }
                    }
                }
            }

            return(shoppingCartItems);
        }
Example #4
0
        public HttpResponseMessage GetDishesByCategoryId(int id = 1)
        {
            DishesBuss buss   = new DishesBuss();
            var        dishes = buss.GetDishes(id);

            foreach (var item in dishes)
            {
                item.ImgUrl = @"http://10.0.2.2:8081/Imgs/products/" + item.Id + ".jpeg";
            }

            return(ToJson(new { Dishes = dishes }));
        }
        private List <ShoppingCartItem> OperateShoppingCart(int id, int qty)
        {
            DishesBuss buss = new DishesBuss();
            List <ShoppingCartItem> shoppingCartItems = null;

            var jser = new JavaScriptSerializer();

            if (Request.Cookies["shoppingCart"] != null)
            {
                var cookieJson = Request.Cookies["shoppingCart"].Value;
                shoppingCartItems = jser.Deserialize <List <ShoppingCartItem> >(cookieJson);
            }

            if (shoppingCartItems == null || shoppingCartItems.Count == 0)
            {
                shoppingCartItems = new List <ShoppingCartItem>();
            }

            var isContaint = false;
            var index      = 0;

            foreach (var item in shoppingCartItems)
            {
                if (item.ItemID == id && qty > 0)
                {
                    item.Qty   = qty;
                    isContaint = true;
                    break;
                }

                if (item.ItemID == id && qty == 0)
                {
                    isContaint = true;
                    break;
                }

                index++;
            }

            if (qty == 0)
            {
                shoppingCartItems.RemoveAt(index);
            }


            if (isContaint == false)
            {
                var dishInfo = buss.GetSingleDishes(id);

                ShoppingCartItem cartitem = new ShoppingCartItem();
                cartitem.ItemID = id;
                cartitem.Qty    = qty;
                cartitem.EName  = dishInfo.EName;
                //cartitem.OName = dishInfo.OtherName;
                cartitem.Price = dishInfo.Price;

                shoppingCartItems.Add(cartitem);
            }

            var json = jser.Serialize(shoppingCartItems);

            Response.Cookies["shoppingCart"].Value   = json;
            Response.Cookies["shoppingCart"].Expires = DateTime.Now.AddHours(1);

            return(shoppingCartItems);
        }