public IActionResult Index(string activeConf = "all", string activeDiv = "all")
        {
            var session = new NFLSession(HttpContext.Session);

            session.SetActiveConf(activeConf);
            session.SetActiveDiv(activeDiv);

            var model = new TeamListViewModel
            {
                ActiveConf  = activeConf,
                ActiveDiv   = activeDiv,
                Conferences = context.Conferences.ToList(),
                Divisions   = context.Divisions.ToList()
            };

            IQueryable <Team> query = context.Teams;

            if (activeConf != "all")
            {
                query = query.Where(
                    t => t.Conference.ConferenceID.ToLower() == activeConf.ToLower());
            }
            if (activeDiv != "all")
            {
                query = query.Where(
                    t => t.Division.DivisionID.ToLower() == activeDiv.ToLower());
            }
            model.Teams = query.ToList();

            return(View(model));
        }
Exemplo n.º 2
0
        public IActionResult Index(string activeConf = "all", string activeDiv = "all")
        {
            var session = new NFLSession(HttpContext.Session);

            session.SetActiveConf(activeConf);
            session.SetActiveDiv(activeDiv);

            int?count = session.GetMyTeamCount();

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

                List <Team> myteams = new List <Team>();

                if (ids.Length > 0)
                {
                    myteams = context.Teams
                              .Include(c => c.Conference)
                              .Include(d => d.Division)
                              .Where(t => ids.Contains(t.TeamID))
                              .ToList();
                }

                session.SetMyTeams(myteams);
            }


            var data = new TeamListViewModel
            {
                ActiveConf  = activeConf,
                ActiveDiv   = activeDiv,
                Conferences = context.Conferences.ToList(),
                Divisions   = context.Divisions.ToList()
            };

            IQueryable <Team> query = context.Teams;

            if (activeConf != "all")
            {
                query = query.Where(t => t.Conference.ConferenceID.ToLower() == activeConf.ToLower());
            }
            if (activeDiv != "all")
            {
                query = query.Where(t => t.Division.DivisionID.ToLower() == activeDiv.ToLower());
            }

            data.Teams = query.ToList();

            return(View(data));
        }
Exemplo n.º 3
0
        public IActionResult Index(TeamListViewModel model)
        {
            model.Conferences = context.Conferences.ToList();
            model.Divisions   = context.Divisions.ToList();

            var session = new NFLSession(HttpContext.Session);

            session.SetActiveConf(model.ActiveConf);
            session.SetActiveDiv(model.ActiveDiv);

            // if no count value in session, use data in cookie to restore fave teams in session
            int?count = session.GetMyTeamCount();

            if (count == null)
            {
                var      cookies = new NFLCookies(HttpContext.Request.Cookies);
                string[] ids     = cookies.GetMyTeamIds();

                List <Team> myteams = new List <Team>();
                if (ids.Length > 0)
                {
                    myteams = context.Teams.Include(t => t.Conference)
                              .Include(t => t.Division)
                              .Where(t => ids.Contains(t.TeamID)).ToList();
                }
                session.SetMyTeams(myteams);
            }

            IQueryable <Team> query = context.Teams;

            if (model.ActiveConf != "all")
            {
                query = query.Where(
                    t => t.Conference.ConferenceID.ToLower() == model.ActiveConf.ToLower());
            }
            if (model.ActiveDiv != "all")
            {
                query = query.Where(
                    t => t.Division.DivisionID.ToLower() == model.ActiveDiv.ToLower());
            }
            model.Teams = query.ToList();

            return(View(model));
        }