public JsonResult GetDanhSachYeuThich(List <int> IdYeuThics)
        {
            string listids = string.Join(",", IdYeuThics);
            IList <ProductFrontPageMapping.ProductBox>     products   = _menuRepository.LaySanPhamYeuThichs(listids);
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            PromotionMapping.PromotionCheck promotion = _promotionRepository.GetCurrentPromotion();
            foreach (var sp in products)
            {
                if (promotions.Any())
                {
                    foreach (var pr in promotions)
                    {
                        var promotionDetail = pr.PromotionDetails.FirstOrDefault(dt => dt.ProductId == sp.id_);
                        if (promotionDetail != null)
                        {
                            sp.HasPromotion   = true;
                            sp.PricePromotion = (int)promotionDetail.PriceDiscount;
                            sp.Discount       = (short)promotionDetail.Percent;
                            break;
                        }
                    }
                }
            }
            DanhSach model = new DanhSach()
            {
                DanhSachYeuThichs = products
            };

            TempData["DanhSach"] = model;

            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult UpdateCartPopup()
        {
            IList <CartViewModel.ProductCart> productCarts = new List <CartViewModel.ProductCart>();
            CookieHelper cookieHelper = new CookieHelper("Cart");

            if (cookieHelper.GetCookie() != null)
            {
                string json = HttpUtility.UrlDecode(cookieHelper.GetCookie().Values["Cart"]);
                productCarts = JsonConvert.DeserializeObject <List <CartViewModel.ProductCart> >(json);
            }
            PromotionMapping.PromotionCheck promotion = _promotionRepository.GetCurrentPromotion();

            IList <ProductFrontPageMapping.ProductShowCart> productShowCarts =
                _menuRepository.GetProductShowCartByBarcode(productCarts.Select(o => o.Barcode).ToList());
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();
            IList <CartViewModel.CartItem> cartItems = new List <CartViewModel.CartItem>();
            int gia = 0;

            if (productCarts.Any())
            {
                foreach (var o in productCarts)
                {
                    IList <ProductStockSyncMapping.TonKho> tonKhos = _productStockSyncRepository.GetTonKhoCuaSanPham(o.ProductId);

                    var tonkho = tonKhos.FirstOrDefault(t => t.Barcode.Equals(o.Barcode));
                    var item   = productShowCarts.FirstOrDefault(p => p.Barcode.Equals(o.Barcode));
                    if (item != null)
                    {
                        #region ghép combo < 80K
                        if (item.Price < 80000 && o.Quantity >= 2)
                        {
                            //nếu số lượng > 2  và giá < 80000 bắt đầu tính giá combo
                            int giatru = (item.Price * 10) / 100;
                            gia = item.Price - giatru;
                        }
                        else
                        {
                            gia = item.Price;
                        }
                        #endregion
                        var cartItem = new CartViewModel.CartItem()
                        {
                            ProductId      = o.ProductId,
                            Name           = item.NameProduct,
                            Image          = item.Img,
                            Link           = item.Link,
                            Price          = item.Price,
                            PricePromotion = gia,
                            Barcode        = o.Barcode,
                            Quantity       = o.Quantity <= 0 ? 1 : o.Quantity,
                            AttributeImg   = item.AttributeImg,
                            AttributeName  = item.AttributeName,
                            AttributeFlag  = item.AttributeFlag,
                            Available      = tonkho != null && tonkho.OnHand >= (o.Quantity <= 0 ? 1 : o.Quantity)
                        };

                        #region check promotion
                        if (promotions.Any())
                        {
                            foreach (var pr in promotions)
                            {
                                var promotionDetail = pr.PromotionDetails.FirstOrDefault(dt => dt.ProductId == cartItem.ProductId);
                                if (promotionDetail != null)
                                {
                                    cartItem.HasPromotion   = true;
                                    cartItem.PricePromotion = (int)promotionDetail.PriceDiscount;
                                    cartItem.Discount       = (short)promotionDetail.Percent;
                                    break;
                                }
                            }
                        }

                        #endregion
                        cartItems.Add(cartItem);
                    }
                }
            }
            CartViewModel.CartModel cartModel = new CartViewModel.CartModel()
            {
                CartItems = cartItems,
                Total     = cartItems.Sum(o => o.Quantity * o.PricePromotion),
                Available = cartItems.All(o => o.Available)
            };

            string html = RenderPartialViewToString("ViewRender", cartModel);

            return(Json(new { html = html, countCart = cartModel.CartItems.Count() }, JsonRequestBehavior.AllowGet));
        }