public async Task GetForecastAsync() { IsActivityIndicatorVisible = true; StatusMessage = "Getting current location..."; _cancelSource = new CancellationTokenSource(); Position position = null; _geolocator.DesiredAccuracy = 50; await _geolocator.GetPositionAsync(timeout : 10000, cancelToken : _cancelSource.Token, includeHeading : true).ContinueWith(t => { IsActivityIndicatorVisible = false; if (t.IsFaulted) { IsRefreshButtonVisible = true; var geolocationException = t.Exception.InnerException as GeolocationException; if (geolocationException == null) { StatusMessage = t.Exception.InnerException.ToString(); } else { StatusMessage = geolocationException.Error.ToString(); } } else if (t.IsCanceled) { StatusMessage = "Permission denied, please allow the application to access GPS and refresh."; IsRefreshButtonVisible = true; } else { position = t.Result; } }, scheduler); if (position != null) { IsActivityIndicatorVisible = true; IsRefreshButtonVisible = false; LoadingImage = "Sunny.png"; StatusMessage = "Getting weather forecast..."; Forecast = await _forecastService.GetForecastAsync(position); await _navigation.PopModalAsync(); } }
private async void GetForecast() { var searchCity = string.IsNullOrEmpty(City) ? SelectedCity : City; try { WeatherForecast = await _forecastService.GetForecastAsync(searchCity, Days); Error = null; } catch (Exception ex) { WeatherForecast = null; Error = $"Our application doesn't provide forecast for {searchCity}"; } finally { NotificateView(); } }
private async Task GetForecastAsync() { Loading = true; var forecasts = await ForecastService.GetForecastAsync(); Forecasts = forecasts.Select(f => { var props = new List <DynamicTableCell> { new DynamicTableCell { Content = f.Date, Classes = "-l" }, new DynamicTableCell { Content = f.Temperature, Classes = "-l" }, new DynamicTableCell { Content = f.RainChangePercent, Classes = "-r" }, new DynamicTableCell { Content = f.RainAmmount, Classes = "-r" } }; return(new DynamicTableRow { Cells = props }); }).ToList(); GroupedForecast = forecasts.GroupBy(f => f.Date.Date).Select(g => { var group = new DynamicTableGroup { Title = $"{g.Key.ToShortDateString()} -> Avg temp (C): {Math.Round(g.Average(f => f.Temperature), 1, MidpointRounding.ToEven)}", Rows = g.Select(f => { var props = new List <DynamicTableCell> { new DynamicTableCell { Content = f.Date, Classes = "forecast-date -l" }, new DynamicTableCell { Content = f.Temperature, Classes = "-l" }, new DynamicTableCell { Content = f.RainChangePercent, Classes = "-r" }, new DynamicTableCell { Content = f.RainAmmount, Classes = "-r" } }; return(new DynamicTableRow { Cells = props }); }).ToList() }; return(group); }).ToList(); Loading = false; }
public async Task <IActionResult> Get([FromRoute] string city) { return(Ok(await _forecastService.GetForecastAsync(city))); }