public ForecastDetails GetCurrentWeatherByLocationName(string locationName)
        {
            if (String.IsNullOrEmpty(locationName))
            {
                return(null);
            }

            var externalApiUrl = GetBaseApiUrl()
                                 .SetQueryParams(new
            {
                q = locationName
            });

            try
            {
                var jsonDynamic = externalApiUrl.GetJsonAsync().Result;
                logger.LogInformation($"External weather API returned this result: {jsonDynamic}");
                return(ForecastDetails.ToForecastDetails(jsonDynamic));
            }
            catch (Exception ex)
            {
                logger.LogError($"Exception in GetCurrentWeatherByLocationName: {ex} \nMessage: {ex.Message}");
                return(null);
            }
        }
Esempio n. 2
0
        private void GetForecastDetails(string cityCode = "sb")
        {
            ObservableCollection <ForecastDetails> forecastDetailsCollection = new ObservableCollection <ForecastDetails>();

            forecastDetailsCollection = ForecastDetails.GetForecast(cityCode);
            ForecastDetailsCollection = new ObservableCollection <ForecastDetails>(forecastDetailsCollection);
            RaisePropertyChanged(() => ForecastDetailsCollection);
        }
        public ForecastDetails GetCurrentWeatherByLocationId(int locationId)
        {
            if (locationId < 0)
            {
                return(null);
            }

            var externalApiUrl = GetBaseApiUrl()
                                 .SetQueryParams(new
            {
                id = locationId
            });

            try
            {
                var jsonDynamic = externalApiUrl.GetJsonAsync().Result;
                return(ForecastDetails.ToForecastDetails(jsonDynamic));
            }
            catch (Exception ex)
            {
                logger.LogError($"Exception in GetCurrentWeatherByLocationId: {ex} \nMessage: {ex.Message}");
                return(null);
            }
        }