public async Task <Weather[]> GetForecastAsync(string city, Units units, Langs lang, SortParam sortBy) { var reqUrl = WeatherRequestBuilder.GetForecastUri(city, units, lang); var forecastDto = await RestClient.GetAllAsync <ForecastDto>(reqUrl); var list = forecastDto.List .Select(dto => new Weather { City = city, Date = DateTime.Parse(dto.Day), Temperature = dto.Main.Temperature, TempMin = dto.Main.TempMin, TempMax = dto.Main.TempMax, Pressure = dto.Main.Pressure, Humidity = dto.Main.Humidity, Wind = dto.Wind.Speed, Clouds = dto.Clouds.All, Description = dto.Weather[0]?.Description }); var orderedList = list; if (sortBy != null) { var propertyInfo = typeof(Weather).GetProperties() .FirstOrDefault(x => x.Name.EqualsIgnoreCase(sortBy.Field)); orderedList = sortBy.Asc ? list.OrderBy(x => propertyInfo.GetValue(x, null)) : list.OrderByDescending(x => propertyInfo.GetValue(x, null)); } return(orderedList.ToArray()); }
public async Task <Weather> GetWeatherAsync(string city, Units units, Langs lang) { var reqUrl = WeatherRequestBuilder.GetWeatherUri(city, units, lang); var dto = await RestClient.GetAsync <WeatherDto>(reqUrl); return(new Weather { City = city, Date = DateTime.Parse(dto.Day), Temperature = dto.Main.Temperature, TempMin = dto.Main.TempMin, TempMax = dto.Main.TempMax, Pressure = dto.Main.Pressure, Humidity = dto.Main.Humidity, Wind = dto.Wind.Speed, Clouds = dto.Clouds.All, Description = dto.Weather[0]?.Description }); }