private async Task GetWeatherByCity()
        {
            if (CurrentCityId != 0)
            {
                CurrentWeather = new PeriodWeatherModel {
                    Temperature = 10
                };

                CurrentWeather = await _weatherService.GetCurrentWeatherByCity(CurrentCityId);
            }
        }
Beispiel #2
0
        private PeriodWeatherModel GetPeriodWeatherModel(PartsOfDay title, WeatherInfo item)
        {
            PeriodWeatherModel period = new PeriodWeatherModel
            {
                Title       = title,
                Description = item.Weather[0].Description,
                Humidity    = item.Main.Humidity,
                Clouds      = item.Clouds.All,
                WindSpeed   = item.Wind.Speed,
                Temperature = Convert.ToInt32(item.Main.Temp),
                Date        = item.Dt_txt,
                GroundLevel = item.Main.Grnd_level,
                SeaLevel    = item.Main.Sea_level,
                TempMax     = Convert.ToInt32(item.Main.Temp_max),
                TempMin     = Convert.ToInt32(item.Main.Temp_min),
                Pressure    = item.Main.Pressure
            };

            return(period);
        }
Beispiel #3
0
        public async Task <PeriodWeatherModel> GetCurrentWeatherByCity(int id)
        {
            try
            {
                string templateUrl = $"{Constants.ApiUrl}/weather/?id={id}&appid={Constants.ApiKey}";
                var    degreeType  = await SecureStorage.GetAsync("DegreeType");

                if (degreeType == DegreeType.Celsius.ToString())
                {
                    templateUrl = $"{templateUrl}&units=metric";
                }
                WeatherInfo response = await _httpClientHelper.PerformGet <WeatherInfo>(templateUrl);

                PeriodWeatherModel periodWeatherModel = GetPeriodWeatherModel(PartsOfDay.defaultPart, response);
                return(periodWeatherModel);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
 private void DegreeTypePropertyChangedForecast(DegreeEventArgs obj)
 {
     CurrentWeather = null;
     GetWeatherByCity().ConfigureAwait(false);
 }