public IActionResult GetWeather(string Country, string City) { try { Country = Country.Trim(); City = City.Trim(); if (_weatherDataService.CheckCountryCityExist(Country, City)) { return(Ok(_weatherDataService.GetWeather(Country, City))); } else { return(NotFound(string.Format("{0} City does not exist in {1}", City, 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)); }