public IHttpActionResult Post([FromBody] TownRequest town) { try { return(Ok(Reports.SalesByRegion.Report(town.Name))); } catch (Exception ex) { Logger.Log(ex.Message); return(BadRequest("Town not found")); } }
public async Task <WeatherTown> GetAsync(TownRequest town) { var weatherTown = _weatherStorage.Get(town.Name); if (weatherTown == null) { weatherTown = await GetWeather(town); _weatherStorage.Create(weatherTown); } return(weatherTown); }
public async Task <IEnumerable <WeatherForecast> > WeatherForecasts([FromQuery] TownRequest town) { if (town == null || string.IsNullOrEmpty(town.Name)) { return(_dataProvider.GetAll()?.Select(x => x.ToForecast())); //throw new Exception("укажиите город"); } try { var weather = await _dataProvider.GetAsync(town); return(new WeatherForecast[] { weather.ToForecast() }); } catch (WeatherException ex) { throw new Exception(ex.Message); } }
private async Task <WeatherTown> GetWeather(TownRequest town) { return(await _weatherHttpClient.GetAsync(town.Name)); }