Пример #1
0
        public async Task OnGetAsync()
        {
            InfoText = string.Empty;
            var stationQueryString = HttpContext.Request.Query["stationName"].ToString();

            if (string.IsNullOrEmpty(stationQueryString))
            {
                FavoriteStation = await _stationService.GetFavoriteStation();
            }
            else
            {
                FavoriteStation = await _stationService.GetFavoriteStation(stationQueryString);
            }

            if (FavoriteStation.AvailableBikes == 0)
            {
                InfoText        = $"{FavoriteStation.Name} had no available bikes. Showing closest bikestation.";
                FavoriteStation = await _stationService.GetClosestAvailableStation(FavoriteStation);
            }

            if (WeatherServiceEnabled)
            {
                WeatherForecastReport weatherForecastReport;
                try
                {
                    weatherForecastReport = await _weatherService.GetDailyForeCastAsync(FavoriteStation.StationCoordinates);

                    WeatherForecastViewModels = GetForecastViewModels(weatherForecastReport.Forecasts);
                }
                catch (NotImplementedException exception)
                {
                    WeatherServiceEnabled = false;
                }
            }
        }
Пример #2
0
        public async Task <StationWeatherDTO> GetAsync([FromQuery(Name = "stationName")] string stationName)
        {
            FavoriteStation       station;
            WeatherForecastReport weatherForecast;
            var showingClosestStationWithBikes = false;
            var originalStationName            = "";

            if (string.IsNullOrEmpty(stationName))
            {
                station = await _stationService.GetFavoriteStation();
            }
            else
            {
                station = await _stationService.GetFavoriteStation(stationName);
            }

            if (station.AvailableBikes == 0)
            {
                originalStationName            = station.Name;
                showingClosestStationWithBikes = true;
                station = await _stationService.GetClosestAvailableStation(station);
            }

            if (_weatherService.FeatureEnabled)
            {
                weatherForecast = await _weatherService.GetDailyForeCastAsync(station.StationCoordinates);
            }
            else
            {
                weatherForecast = new WeatherForecastReport(new WeatherForecast[] { });
            }
            return(new StationWeatherDTO
            {
                Station = station,
                OriginalStationName = originalStationName,
                ShowingClosestStationWithBikes = showingClosestStationWithBikes,
                ForecastReport = weatherForecast
            });
        }