public IActionResult GetCities(string Country) { try { Country = Country.Trim(); if (_weatherDataService.CheckCountryExist(Country)) { return(Ok(_weatherDataService.GetCityList(Country))); } else { return(NotFound(string.Format("{0} not found", Country))); } } catch { //log error return(StatusCode((int)HttpStatusCode.InternalServerError, "Server offline please try again later")); } }
public ActionResult Index() { WeatherDataViewModel model = new WeatherDataViewModel(); model.Countries = _weatherDataService.GetCountryList(). Select(country => new SelectListItem() { Text = country, Value = country }).ToList(); model.Cities = _weatherDataService.GetCityList(model.Countries[0].Value). Select(City => new SelectListItem() { Text = City, Value = City }).ToList(); model.Country = model.Countries[0].Value; model.City = model.Cities[0].Value; model.CityWeatherData = _weatherDataService.GetWeather(model.Countries[0].Value, model.Cities[0].Value); return(View(model)); }