/// <summary> /// Gets the properties to the current weather from the WeatherForecast class and sets the values to the properties of the ForecastResult class that both bestweather and worstweather uses. /// </summary> /// <param name="key"></param> /// <param name="bestweather"></param> /// <param name="forecast"></param> /// <returns></returns> private static ForecastResult GetCurrentWorstWeather(int key, ForecastResult worstweather, WeatherForecast forecast) { worstweather.Dt = string.Format("{0}", FormatFunction.getDate(forecast.list[key].Dt)); worstweather.City = string.Format("{0}", forecast.city.Name); worstweather.Temperature = string.Format("{0}", FormatFunction.getCelsius(forecast.list[key].main.Temp)); worstweather.Weather = string.Format("{0}", forecast.list[key].weather[0].Main); worstweather.Description = string.Format("{0}", forecast.list[key].weather[0].Description); return(worstweather); }
/// <summary> /// We uses the weather_object we got from the GetJson method calling from WeatherAPI:s constructor and set values to the WeatheData model the method returns. /// </summary> /// <param name="destination"></param> /// <returns> WeatherData</returns> public WeatherData GetWeather(string destination) { string temp_string = ""; WeatherData data = new WeatherData(); data.Weather = weather_object != null ? weather_object.weather[0].main : null; data.Description = weather_object != null ? weather_object.weather[0].description : null; data.CurrentTime = weather_object != null?string.Format("{0}", FormatFunction.getDate(weather_object.dt)) : null; temp_string = weather_object != null?string.Format("{0}", FormatFunction.getCelsius(weather_object.main.temp).ToString()) : null; data.Temp = float.Parse(string.Format("{0}", temp_string, CultureInfo.InvariantCulture)); data.Cloudyness = currentWeather = weather_object != null?weather_object.clouds.all.ToString() : null; data.Destination = destination; return(data); }