Exemplo n.º 1
0
        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 CountrySession(HttpContext.Session);
            var countries = session.GetMyCountries();

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

            var cookies = new CountryCookies(Response.Cookies);

            cookies.SetMyCountryIds(countries);

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

            return(RedirectToAction("Index",
                                    new
            {
                ActiveGame = session.GetActiveGame(),
                ActiveSport = session.GetActiveSport()
            }));
        }
Exemplo n.º 2
0
        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()
            }));
        }
Exemplo n.º 3
0
        public ViewResult Details(string id)
        {
            var session = new CountrySession(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));
        }