Beispiel #1
0
        public IActionResult Index()
        {
            var session = new OlympicSession(HttpContext.Session);
            var model   = new OlympicListViewModel
            {
                ActiveGame  = session.GetActiveGame(),
                ActiveSport = session.GetActiveSport(),
                Countries   = session.GetMyCountries()
            };

            return(View(model));
        }
Beispiel #2
0
        public IActionResult Index(OlympicListViewModel model, string activeGame = "all", string activeSport = "all")
        {
            var session = new CountrySession(HttpContext.Session);

            session.SetActiveGame(activeGame);
            session.SetActiveSport(activeSport);


            int?count = session.GetMyCountryCount();

            if (count == null)
            {
                var      cookies = new CountryCookies(Request.Cookies);
                string[] ids     = cookies.GetMyCountryIds();

                List <Country> mycountries = new List <Country>();
                if (ids.Length > 0)
                {
                    mycountries = context.Countries.Include(testc => testc.Game)
                                  .Include(t => t.Sport)
                                  .Where(t => ids.Contains(t.CountryID)).ToList();
                }
                session.SetMyCountries(mycountries);
            }


            model.Games  = context.Games.ToList();
            model.Sports = context.Sports.ToList();

            IQueryable <Country> query = context.Countries;

            if (activeGame != "all")
            {
                query = query.Where(t => t.Game.GameID.ToLower() == activeGame.ToLower());
            }
            if (activeSport != "all")
            {
                query = query.Where(t => t.Sport.SportID.ToLower() == activeSport.ToLower());
            }
            model.Countries = query.ToList();
            return(View(model));
        }