Exemplo n.º 1
0
        private void UpdateCurrentWeatherData(CurrentWeatherConditions currentWeatherData)
        {
            _dawn = UnixTimeStampUtility.UnixTimeStampToDateTime(currentWeatherData?.sys?.sunrise ?? 0).TimeOfDay;
            _dusk = UnixTimeStampUtility.UnixTimeStampToDateTime(currentWeatherData?.sys?.sunset ?? 0).TimeOfDay;

            var icons = GetIcons(DateTime.Now.TimeOfDay, _dawn, _dusk);

            CurrentWeather = new ForecastViewModel(new Forecast
            {
                Temperature   = currentWeatherData?.main?.temp ?? 0,
                WeatherTypeId = currentWeatherData.weather.FirstOrDefault()?.id
            }, icons);
        }
Exemplo n.º 2
0
        private async Task UpdateForecastWeatherData(IEnumerable <Forecast> forecasts)
        {
            forecasts = forecasts.OrderBy(f => f.Date).Where(f => f.Date > DateTime.Now && f.Date.Date >= DateTime.Today && f.Date.Date <= DateTime.Today.AddDays(1));

            foreach (var forecast in forecasts.Take(FORCAST_LENGHT))
            {
                var existingForcastVM = Forecasts.FirstOrDefault(f => f.Date == forecast.Date);

                if (existingForcastVM != null)
                {
                    existingForcastVM.Update(forecast);
                }
                else
                {
                    var icons = GetIcons(forecast.Date.TimeOfDay, _dawn, _dusk);

                    var forecastVM = new ForecastViewModel(forecast, icons);

                    Forecasts.Add(forecastVM);

                    await forecastVM.Init();
                }
            }
        }