public async Task <ActionResult> Index(string searchTerm, string searchCategory, int?page) { //Background Tasks try { Cron.SearchForExpiredproduct(); Cron.AddProductToAuctionTable(); Cron.SendInventoryEmails(); } catch (Exception e) { string error = ""; //foreach (var item in e.EntityValidationErrors) //{ // error += item.Entry; //} return(Content(e.Message + "||||" + e.StackTrace)); } var models = new List <Product>(); if (!string.IsNullOrWhiteSpace(searchTerm) && !string.IsNullOrWhiteSpace(searchCategory)) { models = await ProductRepo.GetAll(x => x.StoreId == LoggedInUser.StoreId).Where(x => x.Category == searchCategory && x.Name.ToLower().Contains(searchTerm.ToLower()) == true).ToListAsync(); } else if (!string.IsNullOrWhiteSpace(searchTerm) && string.IsNullOrWhiteSpace(searchCategory)) { models = await ProductRepo.GetAll(x => x.StoreId == LoggedInUser.StoreId).Where(x => x.Name.ToLower().Contains(searchTerm.ToLower()) == true).ToListAsync(); } else if (string.IsNullOrWhiteSpace(searchTerm) && !string.IsNullOrWhiteSpace(searchCategory)) { models = await ProductRepo.GetAll(x => x.StoreId == LoggedInUser.StoreId).Where(x => x.Category == searchCategory).ToListAsync(); } else { models = await ProductRepo.GetAll(x => x.StoreId == LoggedInUser.StoreId).ToListAsync(); } if (string.IsNullOrWhiteSpace(searchCategory)) { ViewBag.Catgory = searchCategory; ViewBag.SearchTerm = searchTerm; } int pageNumber = (page ?? 1); var result = await FetchCategories(); ViewBag.Categories = result; return(View(models.ToPagedList(pageNumber, PageSize))); }