public RedirectToActionResult Add(OlympicViewModel model)
        {
            model.Country = context.Countries
                            .Include(t => t.Game)
                            .Include(t => t.Sport)
                            .Where(t => t.CountryID == model.Country.CountryID)
                            .FirstOrDefault();

            var session   = new OlympicSession(HttpContext.Session);
            var countries = session.GetMyCountries();

            countries.Add(model.Country);
            session.SetMyCountries(countries);

            /*creates new OlympicCookies object with the controller's response object.
             * calls SetMyCountryIds and passes updated list of Country objects.
             */
            var cookies = new OlympicCookies(Response.Cookies);

            cookies.SetMyCountryIds(countries);

            TempData["message"] = $"{model.Country.CountryName} added to your favorites"; //message

            return(RedirectToAction("Index",                                              //redirection
                                    new
            {
                ActiveGame = session.GetActiveGame(),
                ActiveSport = session.GetActiveSport()
            }));
        }
Beispiel #2
0
        public RedirectToActionResult Add(CountryViewModel model)
        {
            model.Country = context.Countries
                            .Include(t => t.Game)
                            .Include(t => t.Category)
                            .Where(t => t.CountryID == model.Country.CountryID)
                            .FirstOrDefault();

            var session   = new OlympicSession(HttpContext.Session);
            var countries = session.GetMyCountries();

            countries.Add(model.Country);
            session.SetMyCountries(countries);

            var cookies = new OlympicCookies(Response.Cookies);

            cookies.SetMyCountryIds(countries);

            TempData["message"] = $"{model.Country.Name} added to your favorites";

            return(RedirectToAction("Index",
                                    new
            {
                ActiveGame = session.GetActiveGame(),
                ActiveCategory = session.GetActiveCategory()
            }));
        }
Beispiel #3
0
        public ViewResult Index()
        {
            var session = new OlympicSession(HttpContext.Session);
            var model   = new CountryListViewModel
            {
                ActiveGame     = session.GetActiveGame(),
                ActiveCategory = session.GetActiveCategory(),
                Countries      = session.GetMyFavs()
            };

            return(View(model));
        }
Beispiel #4
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 #5
0
        public RedirectToActionResult Add(CountryViewModel model)
        {
            var country = context.Countries.Where(c => c.CountryID == model.CountryID).FirstOrDefault();

            model.Name     = country.Name;
            model.Abbr     = country.Abbr;
            model.Game     = country.Game;
            model.Sport    = country.Sport;
            model.Category = country.Category;

            var session = new OlympicSession(HttpContext.Session);

            if (ModelState.IsValid)
            {
                var favs = session.GetMyFavs();
                favs.Add(country);
                session.SetMyFavs(favs);

                var cookies = new FavoriteCookies(Response.Cookies);
                cookies.SetFavoriteIds(favs);

                TempData["message"] = $"{country.Name} added to favorites";

                return(RedirectToAction("Index", new
                {
                    ActiveGame = session.GetActiveGame(),
                    ActiveCategory = session.GetActiveCategory()
                }));
            }
            else
            {
                TempData["message"] = $"There was an error adding {country.Name} to favorites";
                return(RedirectToAction("Index", new
                {
                    ActiveGame = session.GetActiveGame(),
                    ActiveCategory = session.GetActiveCategory()
                }));
            }
        }
        public ViewResult Details(string id)
        {
            var session = new OlympicSession(HttpContext.Session);
            var model   = new OlympicViewModel
            {
                Country = context.Countries
                          .Include(t => t.Game)
                          .Include(t => t.Sport)
                          .FirstOrDefault(t => t.CountryID == id),
                ActiveSport = session.GetActiveGame(),
                ActiveGame  = session.GetActiveSport()
            };

            return(View(model));
        }
        public RedirectToActionResult Delete()
        {
            var session = new OlympicSession(HttpContext.Session);

            session.RemoveMyCountries();

            TempData["message"] = "Favorite countries cleared";

            return(RedirectToAction("Index", "Country",
                                    new
            {
                ActiveGame = session.GetActiveGame(),
                ActiveCat = session.GetActiveCat()
            }));
        }
Beispiel #8
0
        public RedirectToActionResult Delete()
        {
            var session = new OlympicSession(HttpContext.Session);
            var cookies = new FavoriteCookies(Response.Cookies);

            session.RemoveMyFavs();
            cookies.RemoveMyTeamIds();

            TempData["message"] = "Favorites cleared";

            return(RedirectToAction("Index", "Home", new
            {
                game = session.GetActiveGame(),
                category = session.GetActiveCategory()
            }));
        }
Beispiel #9
0
        public ViewResult Details(int id)
        {
            var session            = new OlympicSession(HttpContext.Session);
            CountryViewModel model = new CountryViewModel();

            var country = context.Countries.Where(c => c.CountryID == id).FirstOrDefault();

            model.Name           = country.Name;
            model.Abbr           = country.Abbr;
            model.Game           = country.Game;
            model.Sport          = country.Sport;
            model.Category       = country.Category;
            model.ActiveGame     = session.GetActiveGame();
            model.ActiveCategory = session.GetActiveCategory();

            return(View(model));
        }
Beispiel #10
0
        public RedirectToActionResult Delete()
        {
            var session = new OlympicSession(HttpContext.Session);
            var cookies = new OlympicCookies(Response.Cookies);

            session.RemoveMyCountries();
            cookies.RemoveMyCountryIds();

            TempData["message"] = "Favorite countries cleared";

            return(RedirectToAction("Index", "Home",
                                    new
            {
                ActiveGame = session.GetActiveGame(),
                ActiveSport = session.GetActiveSport()
            }));
        }
Beispiel #11
0
        public ViewResult Details(string id)
        {
            var session = new OlympicSession(HttpContext.Session);
            var model   = new CountryViewModel
            {
                Country = context.Countries
                          .Include(c => c.Game)
                          .Include(c => c.Sport)
                          .FirstOrDefault(c => c.CountryID == id),
                //ActiveSport = TempData.Peek("ActiveSport").ToString() ,
                //ActiveGame = TempData.Peek("ActiveGame").ToString()
                ActiveSport = session.GetActiveSport(),
                ActiveGame  = session.GetActiveGame()
            };

            return(View(model));
        }