Esempio n. 1
0
 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"));
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
 private async Task <WeatherTown> GetWeather(TownRequest town)
 {
     return(await _weatherHttpClient.GetAsync(town.Name));
 }