Example #1
0
        public async Task <IActionResult> GetWeather(string key)
        {
            try
            {
                Weather weather = localWeatherRepository.GetWeather(key);

                if (weather == null || weather.weatherKey == null)
                {
                    weather = await apiWeatherRepository.GetCityWeather(key);

                    weather = localWeatherRepository.AddWeather(weather);
                }
                else
                {
                    DateTime nowTime     = DateTime.Now;
                    DateTime epoch       = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    long     second      = weather.weatherEpochTime + 11250;
                    DateTime weatherTime = epoch.AddSeconds(second);

                    if ((nowTime - weatherTime).TotalMinutes > 180)
                    {
                        weather = await apiWeatherRepository.GetCityWeather(key);

                        weather = localWeatherRepository.UpdateWeather(weather);
                    }
                }
                return(Ok(weather));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }
Example #2
0
        public async Task <IActionResult> GetCityWeather(string key)
        {
            try
            {
                Weather weather = await apiWeatherRepository.GetCityWeather(key);

                return(Ok(weather));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }