public async Task <WeatherDataModel> DownloadWeatherAsync(string city)
        {
            var jsonString = await GetWeatherAsync(city.ToLower());

            if (string.IsNullOrEmpty(jsonString))
            {
                throw new ArgumentOutOfRangeException(nameof(city));
            }

            var weatherFromJson = Openweatherdata.FromJson(jsonString);

            return(WeatherInfoMapper.Map(weatherFromJson));
        }
Example #2
0
 public static WeatherDataModel Map(Openweatherdata openweather)
 {
     return(new WeatherDataModel
     {
         CityName = openweather.Name,
         Country = openweather.Sys.Country,
         Description = openweather.Weather[0].Description,
         Humidity = openweather.Main.Humidity,
         Icon = GetIcon(openweather.Weather[0].Icon),
         Longitude = (decimal)openweather.Coord.Lon,
         Latitude = (decimal)openweather.Coord.Lat,
         Sunrise = DateTimeOffset.FromUnixTimeSeconds(openweather.Sys.Sunrise).DateTime,
         Sunset = DateTimeOffset.FromUnixTimeSeconds(openweather.Sys.Sunset).DateTime,
         Temperature = (decimal)openweather.Main.Temp,
         WindDirection = (decimal)openweather.Wind.Deg,
         WindSpeed = (decimal)openweather.Wind.Speed
     });
 }