private async Task RefreshTeams() { MobileServiceInvalidOperationException exception = null; try { // This code refreshes the entries in the list view by querying the TodoItems table. // The query excludes completed TodoItems MyProgressRing.Visibility = Visibility.Visible; //tournamentTeams = await tournamentTeamsTable.Where(p => p.TournamentId == TournamentIdTextBlock.Text).ToCollectionAsync(); //var teamsIds = tournamentTeams.Select(p => p.TeamId).ToArray(); //if (teamsIds.Length != 0) // teams = await teamsTable.Where(p => teamsIds.Contains(p.Id)).ToCollectionAsync(); tournamentTeams = await tournamentTeamsTable.Where(p => p.TournamentId == TournamentIdTextBlock.Text).ToCollectionAsync(); teams = await teamsTable.ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { exception = e; } if (exception != null) { await new MessageDialog(exception.Message, "Error loading teams").ShowAsync(); } else { var specificTeams = teams.Join(tournamentTeams, t => t.Id, tT => tT.TeamId, (t, tT) => new { Id = t.Id, Name = t.Name, Wins = tT.TeamWins, Points = tT.TeamPoints }) .OrderByDescending(p => p.Points).OrderByDescending(p => p.Wins); TeamsListListView.ItemsSource = specificTeams; MyProgressRing.Visibility = Visibility.Collapsed; tournamentTeams = await tournamentTeamsTable.Where(p => p.TournamentId == TournamentIdTextBlock.Text).ToCollectionAsync(); var numberOfTeams = tournamentTeams.Count; var teamsIds = tournamentTeams.Select(p => p.TeamId).ToArray(); if (numberOfTeams < 4) { AssignTeamsTextBlock.Visibility = Visibility.Visible; } } }
private async Task RefreshMatches() { MobileServiceInvalidOperationException exception = null; try { // This code refreshes the entries in the list view by querying the TodoItems table. // The query excludes completed TodoItems MyProgressRing.Visibility = Visibility.Visible; matches = await matchesTable.Where(p => p.TournamentId == TournamentIdTextBlock.Text).OrderBy(p => p.Nr).ToCollectionAsync(); var matchesIds = matches.Select(p => p.Id).ToArray(); teams = await teamsTable.ToCollectionAsync(); if (matchesIds.Length != 0) { matches = await matchesTable.Where(p => matchesIds.Contains(p.Id)).ToCollectionAsync(); } } catch (MobileServiceInvalidOperationException e) { exception = e; } if (exception != null) { await new MessageDialog(exception.Message, "Error loading matches.").ShowAsync(); } else { var matchesTeams = matches.Join(teams, m => m.TeamOneId, t => t.Id, (m, t) => new { Id = m.Id, TeamOneId = m.TeamOneId, TeamTwoId = m.TeamTwoId, TeamOneScore = m.TeamOneScore, TeamTwoScore = m.TeamTwoScore, TeamOneName = t.Name, Ended = m.Ended, Nr = m.Nr, TournamentId = m.TournamentId }); var matchesTeams2 = matchesTeams.Join(teams, m => m.TeamTwoId, t => t.Id, (m, t) => new GameHelper { Id = m.Id, TeamOneId = m.TeamOneId, TeamTwoId = m.TeamTwoId, TeamOneScore = m.TeamOneScore, TeamTwoScore = m.TeamTwoScore, TeamOneName = m.TeamOneName, TeamTwoName = t.Name, Ended = m.Ended, Nr = m.Nr, TournamentId = m.TournamentId }); MatchesListListView.ItemsSource = matchesTeams2; MyProgressRing.Visibility = Visibility.Collapsed; } }