Exemple #1
0
        public List <int> getFavoritesCache()
        {
            List <int> favorites = new List <int>();

            if (this.memoryCache.Get("Favorites") != null)
            {
                favorites = ToolkitService.DeserializeJsonObject <List <int> >
                                (this.memoryCache.Get("Favorites").ToString());
            }
            return(favorites);
        }
Exemple #2
0
        public List <Cart> GetCartCache()
        {
            List <Cart> cart = new List <Cart>();

            if (this.memoryCache.Get("Cart") != null)
            {
                cart = ToolkitService.DeserializeJsonObject <List <Cart> >
                           (this.memoryCache.Get("Cart").ToString());
            }
            return(cart);
        }
Exemple #3
0
        public void SaveCartCache(int product_id, int size_id, int amount)
        {
            List <Cart> cart = new List <Cart>();

            if (this.memoryCache.Get("Cart") != null)
            {
                cart = ToolkitService.DeserializeJsonObject <List <Cart> >
                           (this.memoryCache.Get("Cart").ToString());
            }
            cart.Add(new Cart(product_id, size_id, amount));
            httpContext.HttpContext.Session.SetInt32("cartItems", cart.Count);
            this.memoryCache.Set("Cart", ToolkitService.SerializeJsonObject(cart));
        }
Exemple #4
0
        public List <int> RemoveFavoriteCache(int productId)
        {
            List <int> favorites = new List <int>();

            if (this.memoryCache.Get("Favorites") != null)
            {
                favorites = ToolkitService.DeserializeJsonObject <List <int> >
                                (this.memoryCache.Get("Favorites").ToString());
            }
            favorites.RemoveAll(x => x == productId);
            httpContext.HttpContext.Session.SetInt32("favs", favorites.Count);
            this.memoryCache.Set("Favorites", ToolkitService.SerializeJsonObject(favorites));
            return(favorites);
        }
Exemple #5
0
        public List <Cart> RemoveCartCache(int product_id, int size_id)
        {
            List <Cart> cart = new List <Cart>();

            if (this.memoryCache.Get("Cart") != null)
            {
                cart = ToolkitService.DeserializeJsonObject <List <Cart> >
                           (this.memoryCache.Get("Cart").ToString());
            }
            cart.RemoveAll(x => x.Product_id == product_id && x.Size_id == size_id);
            httpContext.HttpContext.Session.SetInt32("cartItems", cart.Count);
            this.memoryCache.Set("Cart", ToolkitService.SerializeJsonObject(cart));
            return(cart);
        }
Exemple #6
0
        public List <Cart> EditCartCache(int product_id, int size_id, int amount)
        {
            List <Cart> cart = this.GetCartCache();

            foreach (Cart c in cart)
            {
                if (c.Product_id == product_id && c.Size_id == size_id)
                {
                    //si existe aumentamos su cantidad
                    c.Amount = amount;
                }
            }
            this.memoryCache.Set("Cart", ToolkitService.SerializeJsonObject(cart));
            return(cart);
        }
Exemple #7
0
 public void saveFavoritesCache(int productId)
 {
     if (this.IsFavorite(productId) == false)
     {
         List <int> favorites = new List <int>();
         int        favs      = 0;
         if (this.memoryCache.Get("Favorites") != null)
         {
             favorites = ToolkitService.DeserializeJsonObject <List <int> >
                             (this.memoryCache.Get("Favorites").ToString());
         }
         favorites.Add(productId);
         favs += favorites.Count;
         httpContext.HttpContext.Session.SetInt32("favs", favs);
         this.memoryCache.Set("Favorites", ToolkitService.SerializeJsonObject(favorites));
     }
 }
Exemple #8
0
        public bool IsFavorite(int productId)
        {
            bool       isfav     = false;
            List <int> favorites = new List <int>();

            if (this.memoryCache.Get("Favorites") != null)
            {
                favorites = ToolkitService.DeserializeJsonObject <List <int> >
                                (this.memoryCache.Get("Favorites").ToString());
            }
            foreach (int fav in favorites)
            {
                if (fav == productId)
                {
                    isfav = true;
                    break;
                }
            }
            return(isfav);
        }