예제 #1
0
        private async Task <Tuple <WeatherApiResonseData, OneCallWeatherAPIResponseData> > SearchLocation(string searchInput)
        {
            WeatherApiResonseData         weather        = new WeatherApiResonseData();
            OneCallWeatherAPIResponseData weatherDetails = new OneCallWeatherAPIResponseData();

            if (searchInput.Any(char.IsDigit))
            {
                try
                {
                    weather = await OpenWeatherService.GetCurrentWeatherByZipCodeAsync(searchInput);

                    weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon);
                }
                catch (Exception ex)
                {
                    Debug.Write(ex.Message);
                    weather = await OpenWeatherService.GetCurrentWeatherByCityNameAsync(searchInput);

                    weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon);
                }
            }
            else
            {
                weather = await OpenWeatherService.GetCurrentWeatherByCityNameAsync(searchInput);

                weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon);
            }

            return(Tuple.Create(weather, weatherDetails));
        }