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