protected void PageChanged(object sender, DataGridPageChangedEventArgs e) { products.CurrentPageIndex = e.NewPageIndex; // Get the search terms from the query string string searchKey = WebComponents.CleanString.InputText(Request["keywords"], 100); if (searchKey != "") { // Create a data cache key string cacheKey = "search" + searchKey; // Check if the objects are in the cache if (Cache[cacheKey] != null) { products.DataSource = (IList)Cache[cacheKey]; } else { // If that data is not in the cache then use the business logic tier to fetch the data ProductBO product = new ProductBO(); IList <ProductInfo> productsBySearch = product.GetProductsBySearch(searchKey); // Store the results in a cache Cache.Add(cacheKey, productsBySearch, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration, CacheItemPriority.High, null); products.DataSource = productsBySearch; } // Databind the data to the controls products.DataBind(); } }
public ActionResult Search(string keywords) { string searchKey = CleanString.InputText(keywords, 100); if (searchKey != "") { // Create a data cache key // If that data is not in the cache then use the business logic tier to fetch the data ProductBO product = new ProductBO(); IList <ProductInfo> productsBySearch = product.GetProductsBySearch(searchKey); // Store the results in a cache return(View(productsBySearch)); } return(View()); }
public void ProductBLLTest() { ProductBO productBLL = new ProductBO(); //IList<ProductInfo> products = productBLL.GetProductsByCategory("BIRDS"); //foreach (ProductInfo x in products) //{ // Console.WriteLine("ID: {0}, Name: {1}", x.Id, x.Name); //} //Assert.IsTrue(products.Count > 0); string text = "DOGS CATS MONKEY"; IList <ProductInfo> searchResult = productBLL.GetProductsBySearch(text); Assert.IsTrue(searchResult.Count > 0); foreach (ProductInfo p in searchResult) { Console.WriteLine($"ID: {p.Id} Name: {p.Name} Description: {p.Description}"); } }