//GET api/<controller>/<action>?city={city}&state={state} public async Task <WeatherForecastModel> GetWeatherByCity(string city, string state) { HttpClient client = new HttpClient(); GeolookupModel geoModel = new GeolookupModel(); ForeCastModel forecastModel = new ForeCastModel(); HttpResponseMessage forecastResponse; weatherAPI = weatherAPI.Replace("{{City}}", city).Replace("{{State}}", state); forecastResponse = client.GetAsync(weatherAPI).Result; if (forecastResponse.IsSuccessStatusCode) { forecastModel = await forecastResponse.Content.ReadAsAsync <ForeCastModel>(); } Forecast forecastWeathermodel = new Forecast(); forecastWeathermodel = forecastModel.forecast; Simpleforecast simpleforecast = forecastWeathermodel.simpleforecast; List <Forecastday> forecastdayList = new List <Forecastday>(); forecastdayList = simpleforecast.forecastday; List <WeatherModel> weatherList = new List <WeatherModel>(); WeatherModel weathermodel = null; foreach (Forecastday forecast in forecastdayList) { weathermodel = new WeatherModel(); weathermodel.weekday = forecast.date.weekday; weathermodel.high = forecast.high.fahrenheit; weathermodel.low = forecast.low.fahrenheit; weathermodel.conditions = forecast.conditions; weathermodel.icon_url = forecast.icon_url; weatherList.Add(weathermodel); } WeatherForecastModel weatherForeCastModel = new WeatherForecastModel(); weatherForeCastModel.weatherModel = weatherList; weatherForeCastModel.city.Name = city; weatherForeCastModel.city.State = state; return(weatherForeCastModel); }
public static async Task <ForeCastModel> LoadForecast(int zip) { string url = ""; double longitude; double latitude; int enteredZip = zip; string cityName = "blank"; // set up api call based on input of zip to get coordinates url = string.Format( "http://api.openweathermap.org/data/2.5/weather?zip={0},us&appid=0581321595fd5753f58de82a6035d871", enteredZip); // get response from api call for latitude and longitude using (HttpResponseMessage response = await ApiHelperApiClient.MyApiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) // if response is successful { CorrdByZipModel coordinates = await response.Content.ReadAsAsync <CorrdByZipModel>(); longitude = coordinates.coord.lon; latitude = coordinates.coord.lat; cityName = coordinates.name; } else // if response not successful { throw new Exception(response.ReasonPhrase); } } // sep up api call with newly retrieved values from the last api call url = string.Format( "https://api.openweathermap.org/data/2.5/onecall?lat={0}&lon={1}&exclude=current,minutely,hourly,alerts&appid=0581321595fd5753f58de82a6035d871&units=imperial", latitude, longitude); // make the api call and get response using (HttpResponseMessage response = await ApiHelperApiClient.MyApiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { ForeCastModel report = await response.Content.ReadAsAsync <ForeCastModel>(); report.timezone = cityName; return(report); } throw new Exception(response.ReasonPhrase); } }
public static async Task <ForeCastModel> LoadForecast() { string url = ""; url = "https://api.openweathermap.org/data/2.5/onecall?lat=33.441792&lon=-94.037689&exclude=current,minutely,hourly,alerts&appid=0581321595fd5753f58de82a6035d871&units=imperial"; using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { ForeCastModel report = await response.Content.ReadAsAsync <ForeCastModel>(); return(report); } throw new Exception(response.ReasonPhrase); } }
private async Task LoadForecastReport(int zip) { // load the forecast report object in to the global model currentForeCastModel = await DailyForeCastObject.LoadForecast(zip); }
private async Task LoadForecastReport() { currentForeCastModel = await DailyForeCastObject.LoadForecast(); }