public WeatherForecast ToDomainEntities(AmbeeForecastDTO ambeeForecastDTO, string cityName, bool isImperial) { List <Weather> weatherList = new List <Weather>(); foreach (var forecastWeather in ambeeForecastDTO.data.forecast) { weatherList.Add(ConvertForecastModel(forecastWeather, isImperial)); } var city = ToWeatherCity(ambeeForecastDTO.data.lat, ambeeForecastDTO.data.lng, cityName); return(new WeatherForecast { City = city, WeatherList = weatherList }); }
public async Task <WeatherForecast> GetForecast(double latitude, double longitude, int days) { UriBuilder builder = new UriBuilder(_baseEndpoint) { Path = $"weather/forecast/by-lat-lng", Query = $"lat={latitude.ToString(CultureInfo.InvariantCulture)}&lng={longitude.ToString(CultureInfo.InvariantCulture)}&filter=daily" }; var header = new Dictionary <string, string> { { "x-api-key", _serviceKey } }; AmbeeForecastDTO weatherResponse = await _requestService.GetAsync <AmbeeForecastDTO>(builder.Uri, header); AmbeeMapper ambeeMapper = new AmbeeMapper(); WeatherForecast weatherForecast = ambeeMapper.ToDomainEntities(weatherResponse, _runtimeContext.CityName, _isImperial); weatherForecast.WeatherList = weatherForecast.WeatherList.GetRange(0, days); return(weatherForecast); }