Example #1
0
        public IActionResult ShopList(ShopListOptions options)
        {
            var repo = new EcomRepository();
            var cart = PageMaster.GetShoppingCart();

            int total;
            var model = new ShopListModel
            {
                ShopList = repo.GetShopList(options, cart, out total),
                Brands   = repo.GetAllBrands()
            };

            options.TotalItems = total;

            ViewBag.Options        = options;
            ViewBag.CountCartItems = cart.CartProducts != null?cart.CartProducts.Count() : 0;

            return(View(model));
        }
Example #2
0
        public IActionResult ShopList(ShopListOptions options)
        {
            ShoppingCart cart;

            if (SignInManager.IsSignedIn(User))
            {
                string cartId = UserManager.GetUserId(User);
                cart = Repository.GetCartById(cartId);
            }
            else
            {
                try
                {
                    string requestCookie = HttpContext.Request.Cookies[_cartCookieName];
                    cart = JsonConvert.DeserializeObject <ShoppingCart>(requestCookie);
                }
                catch (Exception)
                {
                    cart = new ShoppingCart()
                    {
                        Id           = Guid.NewGuid().ToString(),
                        CartProducts = new List <CartProduct>()
                    };
                    HttpContext.Response.Cookies
                    .Append(_cartCookieName, JsonConvert.SerializeObject(cart));
                }
            }

            var model = new ShopListModel();
            int total;

            model.ShopList  = Repository.GetShopList(options, cart, out total);
            model.Brands    = Repository.GetAllBrands();
            model.TotalPage = total / (options.PageSize ?? 20);

            ViewBag.Options        = options;
            ViewBag.CountCartItems = cart.CartProducts.Count();
            return(View(model));
        }