Beispiel #1
0
        public WeatherForecast ToDomainEntities(DarkskyForecastDTO darkskyForecastDTO, string cityName)
        {
            List <Weather> weatherList = new List <Weather>();

            foreach (var forecastWeather in darkskyForecastDTO.daily.data)
            {
                weatherList.Add(ConvertForecastModel(forecastWeather));
            }

            var city = ToWeatherCity(darkskyForecastDTO, cityName);

            return(new WeatherForecast {
                City = city, WeatherList = weatherList
            });
        }
Beispiel #2
0
        public async Task <WeatherForecast> GetForecast(double latitude, double longitude, int days)
        {
            UriBuilder builder = new UriBuilder(_baseEndpoint)
            {
                Path  = $"forecast/{_serviceKey}/{latitude.ToString(CultureInfo.InvariantCulture)},{longitude.ToString(CultureInfo.InvariantCulture)}",
                Query = $"exclude=[currently,minutely,hourly,alerts,flags]&units={_unit}&lang={_lang}"
            };

            DarkskyForecastDTO weatherResponse = await _requestService.GetAsync <DarkskyForecastDTO>(builder.Uri);

            DarkskyMapper   darkskyMapper   = new DarkskyMapper();
            WeatherForecast weatherForecast = darkskyMapper.ToDomainEntities(weatherResponse, _runtimeContext.CityName);

            var indexOfTodaysWeahterItem = weatherForecast.WeatherList.FindIndex(x => x.Date.Date == DateTime.Now.Date);

            weatherForecast.WeatherList = weatherForecast.WeatherList.GetRange(indexOfTodaysWeahterItem, days);

            return(weatherForecast);
        }