private void LoadCities() { IsBusy = true; try { Cities = new ObservableCollection <City>(_resourceDataService.GetCities()); } finally { IsBusy = false; } }
private async Task GetFavoriteCitiesAndWeather() { var allCities = _resourceDataService.GetCities(); var favoriteKeys = await _favoriteCityService.GetFavoriteCitiesAsync(); IsBusy = true; if (favoriteKeys.Any()) { NofavoriteCities = false; var favoriteCities = allCities.Where(c => favoriteKeys.Select(f => f.Key).Contains(c.Id)); var tasks = new List <Task>(); foreach (var item in favoriteCities) { tasks.Add(Task.Run(async() => item.Weather = await _restService.GetWeather(item.Id))); } var continuation = Task.WhenAll(tasks); try { continuation.Wait(); Cities = new ObservableCollection <City>(favoriteCities); } catch (Exception) { await _pageDialogService.DisplayAlertAsync(Message.MessageText, Message.FetchWeatherDataFailed, Message.Ok); } finally { IsBusy = false; } } else { NofavoriteCities = true; } }