public ForecastViewModel (INavigation navigation, Forecast forecast) { this.forecast = forecast; this.navigation = navigation; DaysClean = forecast.DaysClean.ToString (); if (forecast.DaysClean == 1) DaysText = "day"; else DaysText = "days"; Reason = forecast.Reason; WeatherList = forecast.WeatherList; }
public async Task<Forecast> GetForecastAsync (Position location) { var openWeatherForecast = await _openWeatherMapService.Get7DayForecastAsync (location); var forecast = new Forecast () { Location = location }; var daysClean = 0; var dtf = new DateTimeFormatInfo (); foreach (var forecastItem in openWeatherForecast.Forecasts) { var weather = forecastItem.WeatherList.FirstOrDefault (); var date = new DateTime (1970, 1, 1).AddSeconds (forecastItem.Dt); forecast.WeatherList.Add (new WeatherViewTemplate { WeatherCondition = weather.Description, DayAbbreviation = dtf.GetAbbreviatedDayName (date.DayOfWeek), TempHigh = Convert.ToInt32(forecastItem.Temperature.Max) + "º", TempLow = Convert.ToInt32(forecastItem.Temperature.Min) + "º", Icon = GetWeatherIcon (weather.Main) }); } foreach (var forecastItem in openWeatherForecast.Forecasts) { var date = new DateTime (1970, 1, 1).AddSeconds (forecastItem.Dt); if (date.Date.Date < DateTime.Now.Date.Date) continue; var weatherForToday = forecastItem.WeatherList [0]; forecast.BadWeatherDay = date; forecast.Reason = ConvertReason (weatherForToday.Main); forecast.ReasonDescription = weatherForToday.Description; if (WeatherIsBad (weatherForToday)) break; daysClean++; } forecast.DaysClean = daysClean; return forecast; }