public RedirectToActionResult Add(CountryViewModel model) { model.Country = context.Countries .Include(c => c.Game) .Include(c => c.Sport) .Include(c => c.Category) .Where(c => c.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(HttpContext.Response.Cookies); cookies.SetMyCountryIds(Countries); TempData["message"] = $"{model.Country.Name} added to your favorites"; return(RedirectToAction("Index", new { ActiveGame = session.GetActiveGame(), ActiveSport = session.GetActiveSport(), ActiveCategory = session.GetActiveCategory() })); }
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() })); }
public IActionResult Details(CountryViewModel model) { model.Country = context.Countries .Include(t => t.Category) .Include(t => t.Game) .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.Name} added to your favorites"; return(RedirectToAction("Index", new { ActiveCat = session.GetActiveCat(), ActiveGam = session.GetActiveGam() })); }
public IActionResult Index(CountryListViewModel model) { var session = new CountrySession(HttpContext.Session); session.SetActiveGame(model.ActiveGame); session.SetActiveSport(model.ActiveSport); session.SetActiveCategory(model.ActiveCategory); // if no count value in session, use data in cookie to restore fave Countries in session int?count = session.GetMyCountryCount(); if (count == null) { var cookies = new CountryCookies(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) .Include(c => c.Category) .Where(c => ids.Contains(c.CountryId)).ToList(); } session.SetMyCountries(myCountries); } model.Games = context.Games.ToList(); model.Sports = context.Sports.ToList(); model.Categories = context.Categories.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()); } if (model.ActiveCategory != "all") { query = query.Where( c => c.Category.CategoryId.ToLower() == model.ActiveCategory.ToLower()); } model.Countries = query.ToList(); return(View(model)); }
public RedirectToActionResult Delete() { var session = new CountrySession(HttpContext.Session); var cookies = new CountryCookies(Response.Cookies); session.RemoveMyCountries(); cookies.RemoveMyCountryIds(); TempData["message"] = "Favorite countries cleared"; return(RedirectToAction("Index", "Country", new { ActiveGame = session.GetActiveGame(), ActiveCat = session.GetActiveCat() })); }
public IActionResult Index(CountryListViewModel model) { model.Categories = context.Categories.ToList(); model.Games = context.Games.ToList(); var session = new CountrySession(HttpContext.Session); session.SetActiveCat(model.ActiveCat); session.SetActiveGam(model.ActiveGam); // if no count value in session, use data in cookie to restore fave teams in session 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(t => t.Category) .Include(t => t.Game) .Where(t => ids.Contains(t.CountryID)).ToList(); } session.SetMyCountries(mycountries); } IQueryable <Country> query = context.Countries; if (model.ActiveCat != "all") { query = query.Where( t => t.Category.CategoryID.ToLower() == model.ActiveCat.ToLower()); } if (model.ActiveGam != "all") { query = query.Where( t => t.Game.GameID.ToLower() == model.ActiveGam.ToLower()); } model.Countries = query.ToList(); return(View(model)); }
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)); }
public ViewResult Index(string activeGame = "0", string activeCat = "0") { var session = new CountrySession(HttpContext.Session); session.SetActiveGame(activeGame); session.SetActiveCat(activeCat); 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(t => t.GameType).Include(t => t.Category).Where(t => ids.Contains(t.CountryId)).ToList(); } session.SetMyCountries(mycountries); } var model = new CountryListViewModel { ActiveGame = activeGame, ActiveCat = activeCat, Games = context.GameTypes.ToList(), Categories = context.Categories.ToList() }; IQueryable <Country> query = context.Countries; if (activeGame != "0") { query = query.Where(t => t.GameType.GameTypeId.ToString() == activeGame); } if (activeCat != "0") { query = query.Where(t => t.Category.CategoryId.ToString() == activeCat); } model.Countries = query.ToList(); return(View(model)); }