public IActionResult Index(CountryListViewModel model) { model.Categories = context.Categories.ToList(); model.Games = context.Games.ToList(); model.Sports = context.Sports.ToList(); var session = new OlympicSession(HttpContext.Session); session.SetActiveGame(model.ActiveGame); session.SetActiveCatg(model.ActiveCatg); session.SetActiveSport(model.ActiveSport); int?count = session.GetMyCountryCount(); if (count == null) { var cookies = new OlympicCookies(Request.Cookies); string[] ids = cookies.GetMyCountryIds(); List <Country> mycountries = new List <Country>(); if (ids.Length > 0) { mycountries = context.Countries.Include(t => t.Game) .Include(t => t.Category) .Include(t => t.Sport) .Where(t => ids.Contains(t.CountryID)).ToList(); } session.SetMyCountries(mycountries); } IQueryable <Country> query = context.Countries; if (model.ActiveGame != "all") { query = query.Where( t => t.Game.GameID.ToLower() == model.ActiveGame.ToLower()); } if (model.ActiveCatg != "all") { query = query.Where( t => t.Category.CategoryID.ToLower() == model.ActiveCatg.ToLower()); } if (model.ActiveSport != "all") { query = query.Where( t => t.Sport.SportID.ToLower() == model.ActiveSport.ToLower()); } model.Countries = query.ToList(); return(View(model)); }