Example #1
0
        public IEnumerable <CityDTOViewModel> GetCities(string filter)
        {
            var client        = new WeatherRestServiceHelper <IEnumerable <CitiesModel> >();
            var requestResult = client.GetCities(filter);
            var cities        = requestResult?.Response;

            if (cities == null || !string.IsNullOrEmpty(requestResult.Error))
            {
                throw new Exception("Failed to get westher from the REST service\n" + requestResult?.Error);
            }

            var result = new List <CityDTOViewModel>();

            result.AddRange(cities.Select(RemapCityView));
            return(result);
        }
Example #2
0
        private WeatherForeCastDtoViewModel GetWeaherForecastFromRestService(string cityId)
        {
            var client  = new WeatherRestServiceHelper <IEnumerable <WeatherForecastModel> >();
            var result  = client.GetWeather(cityId);
            var weather = result?.Response?.FirstOrDefault();

            if (weather == null || !string.IsNullOrEmpty(result.Error))
            {
                throw new Exception("Failed to get westher from the REST service\n" + result?.Error);
            }

            _weatherForecastRepository.AddItem(new WeatherForecast()
            {
                CelsiusTemperature = weather.Temperature.Metric.Value,
                CityId             = cityId,
                WeatherText        = weather.WeatherText,
                DateTime           = weather.LocalObservationDateTime
            });
            return(new WeatherForeCastDtoViewModel
            {
                WeatherText = weather.WeatherText,
                CelsiusTemperature = weather.Temperature.Metric.Value
            });
        }