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)); } }
public IActionResult DeleteCity(string key) { try { int i = localCityRepository.DeleteCity(key); return(NoContent()); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); } }
public IActionResult GetAllCities() { try { List <City> cities = localCityRepository.GetAllCities(); return(Ok(cities)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); } }
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)); } }
public async Task <IActionResult> GetCityCode(string city) { try { List <City> cities = await apiWeatherRepository.GetCityCode(city); return(Ok(cities)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); } }
public IActionResult AddCity(City city) { if (city == null) { return(BadRequest("Data is null.")); } try { City addedCity = localCityRepository.AddCity(city); return(StatusCode(StatusCodes.Status201Created, addedCity)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); } }
public IActionResult AddWeather(Weather weather) { try { if (weather == null) { return(BadRequest("Data is null.")); } Weather addedWeather = localWeatherRepository.AddWeather(weather); return(StatusCode(StatusCodes.Status201Created, addedWeather)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); } }