public ViewResult Index(CountryListViewModel model) { model.Sports = context.Sports.ToList(); model.Games = context.Games.ToList(); //New changes-pg.339. Updates for Chapter 9 for session states var session = new OlympicSession(HttpContext.Session); session.SetActiveGame(model.ActiveGame); session.SetActiveSport(model.ActiveSport); int?count = session.GetMyCountryCount(); if (count == null) { var cookies = new OlympicCookies(HttpContext.Request.Cookies); string[] ids = cookies.GetMyCountryIds(); List <Country> mycountries = new List <Country>(); if (ids.Length > 0) { mycountries = context.Countries.Include(c => c.Game) .Include(c => c.Sport) .Where(c => ids.Contains(c.CountryID)).ToList(); } session.SetMyCountries(mycountries); } //var data = new CountryListViewModel //{ // ActiveGame = activeGame, // ActiveSport = activeSport, // Games = context.Games.ToList(), // Sports = context.Sports.ToList() //}; IQueryable <Country> query = context.Countries; if (model.ActiveGame != "all") { query = query.Where( c => c.Game.GameID.ToLower() == model.ActiveGame.ToLower()); } if (model.ActiveSport != "all") { query = query.Where(c => c.Sport.SportID.ToLower() == model.ActiveSport.ToLower()); } model.Countries = query.ToList(); return(View(model)); }
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)); }