public static async Task <ObservableCollection <Forecast> > GetCoordinateForecast(string lat, string lon) { string queryString = String.Format("Http://api.openweathermap.org/data/2.5/forecast?lat={0}&lon={1}&appid={2}&type=accurate&units=imperial", lat, lon, key); // Json from API dynamic results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); // If Json isnt empty, a collection of Forecast objects is filled with the json if (results["list"][0]["weather"] != null) { DateTime currentTime; ObservableCollection <Forecast> forecastList = new ObservableCollection <Forecast>(); // Loops through every three hours for 5 day API Forecast for (int i = 0; i < 38; i++) { Forecast forecast = new Forecast(); currentTime = time.AddSeconds((double)results["list"][i]["dt"]); // Displays when the next day starts if (currentTime.ToShortTimeString() == "12:00 AM") { forecast.Location = ""; forecast.Temperature = ""; forecast.Description = currentTime.ToShortDateString(); forecast.Time = currentTime.DayOfWeek.ToString(); forecastList.Add(forecast); continue; } // Fills list with forecast for every three hours forecast.Location = (string)results["city"]["name"]; forecast.Temperature = (string)results["list"][i]["main"]["temp"] + " F"; forecast.Description = (string)results["list"][i]["weather"][0]["description"]; forecast.Time = currentTime.ToShortTimeString(); forecastList.Add(forecast); } return(forecastList); } else { return(null); } }
/// <summary> /// Deprecated Method for adding a new object to the Forecasts EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToForecasts(Forecast forecast) { base.AddObject("Forecasts", forecast); }
public override void Add(Forecast forecast) { this._entities.Forecasts.AddObject(forecast); }