private void GetProductByQuery(HttpContext context, string query, int b, int w, int p = 1) { string keyCacheNew = $"query-{query}"; string keyCache = CookieHelper.GetKeyCache(context); if (keyCache == keyCacheNew) { ListProducts = _cache.GetData <List <ProductDTO> >(keyCache); } if (ListProducts == null || ListProducts?.Count == 0) { MapProductDTO(_productSer.FindByQuery(query), ref PageNumber); if (ListProducts.Count == 0) { return; } _cache.AddData(keyCacheNew, ListProducts, TimeSpan.FromMinutes(3)); CookieHelper.AddKeyCache(context, keyCacheNew); } if (ListProducts?.Count > 0) { if (b != 0) { ListProducts = ListProducts.Where(item => item.BandId == b).ToList(); } if (w != 0) { ListProducts = ListProducts.Where(item => item.WireId == w).ToList(); } PageNumber = CalcPage(ListProducts.Count); ListProducts = GetPage(ListProducts, p); } }
private void GetProductByCate(HttpContext context, int category, int b, int w, int p = 1) { MapProductDTO(_productSer.GetListByCate(category, b, w), ref PageNumber); if (ListProducts.Count > 0) { string keyCache = $"c{category},b{b},w{w}"; _cache.AddData(keyCache, ListProducts, TimeSpan.FromMinutes(3)); // CookieHelper.AddKeyCache(context, keyCache); ListProducts = GetPage(ListProducts, p); } }
private void GetProductDiscount(HttpContext context, int b, int w, int p = 1) { if (_lsProm?.Count == 0) { return; } GetProductDiscount(KEY_CACHE_DISCOUNT); // if (ListProducts.Count > 0) { CookieHelper.AddKeyCache(context, KEY_CACHE_DISCOUNT); if (b != 0) { ListProducts = ListProducts.Where(item => item.BandId == b).ToList(); } if (w != 0) { ListProducts = ListProducts.Where(item => item.WireId == w).ToList(); } PageNumber = CalcPage(ListProducts.Count); ListProducts = GetPage(ListProducts, p); } }