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); }
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); }
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)); }
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); }
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); }
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)); } }
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); }