public async Task <ActionResult> Show(PickLinesViewModel lines) { string selectedLines = Request["selectedLines"]; string selectedStation; var cookie = new CookieValues(); var cookieValues = new CookieValues(); if (!CookieExists()) { return(RedirectToAction("Index")); } else { cookie = GetCookieValues(); if (cookie == null) { return(RedirectToAction("Index")); } else if (cookie.MetroId == null) { TempData["CustomError"] = "Du må velge en"; return(RedirectToAction("Stations")); } else if (cookie.StationId == null) { return(RedirectToAction("Index")); } else if (String.IsNullOrEmpty(selectedLines)) { selectedLines = cookie.MetroId; } else if (!String.IsNullOrEmpty(selectedLines)) { var newCookieValues = new CookieValues(); newCookieValues.MetroId = selectedLines; newCookieValues.StationId = cookie.StationId; OverWriteCookieValue(newCookieValues); } } selectedStation = cookie.StationId; List <Tuple <string, string> > metroNameAndDeparture = await _ruterReiseFacade.GetDepartures(selectedStation, selectedLines); DepartureViewModel viewModel = new DepartureViewModel { LineAndDeparture = metroNameAndDeparture, StationName = selectedStation }; return(View("Show", viewModel)); }
public async Task <ActionResult> Stations() { var ruterReiseFacade = new RuterReiseFacade(); string selectedStation = Request["FromStation"]; var cookieValue = new CookieValues { StationId = selectedStation, MetroId = "" }; if (!CookieExists()) { if (String.IsNullOrEmpty(selectedStation)) { return(RedirectToAction("Index")); } SetCookie(cookieValue); } else { if (String.IsNullOrEmpty(selectedStation)) { cookieValue = GetCookieValues(); if (cookieValue == null) { return(RedirectToAction("Index")); } selectedStation = cookieValue.StationId; } else { OverWriteCookieValue(cookieValue); } } if (String.IsNullOrEmpty(selectedStation)) { if (TempData["CustomError"] != null) { ModelState.AddModelError("", TempData["CustomError"].ToString()); } } List <Tuple <int, string, int> > _stationNames = await ruterReiseFacade.GetAllStationsAndLines(); int fromStationId = _stationNames.Find(x => x.Item2.ToLower().Equals(selectedStation.ToLower())).Item3; Dictionary <string, string> linesServingStation = await ruterReiseFacade.GetLinesServingStop(fromStationId); string chooseAllStations = String.Empty; foreach (var lines in linesServingStation) { chooseAllStations = chooseAllStations + lines.Key + ","; } if (linesServingStation.Count > 1) { linesServingStation.Add(chooseAllStations.TrimEnd(','), "Velg alle"); } var viewModel = new PickLinesViewModel { LinesServingStation = linesServingStation }; return(View(viewModel)); }