private async void MatchesListPageButton_Click(object sender, RoutedEventArgs e)
        {
            tournamentTeams = await tournamentTeamsTable.Where(p => p.TournamentId == TournamentIdTextBlock.Text).ToCollectionAsync();

            var teamsIds = tournamentTeams.Select(p => p.TeamId).ToArray();

            if (teamsIds.Length != 4)
            {
                await new MessageDialog("4 drużyny muszą zostać przypisane do turnieju!").ShowAsync();
            }
            else
            {
                Dictionary <string, string> tournamentInfo = new Dictionary <string, string>();

                tournamentInfo["id"]   = TournamentIdTextBlock.Text;
                tournamentInfo["name"] = TournamentNameTextBlock.Text;
                tournamentInfo["date"] = TournamentDateTextBlock.Text;

                TournamentIdTextBlock.Text   = tournamentInfo["id"];
                TournamentNameTextBlock.Text = tournamentInfo["name"];
                TournamentDateTextBlock.Text = String.Format("Data turnieju: {0}.", tournamentInfo["date"]);

                Frame.Navigate(typeof(MatchesListPage), tournamentInfo);
            }
        }
Esempio n. 2
0
        private async Task CreateMatches()
        {
            matches = await matchesTable.Where(p => p.TournamentId == TournamentIdTextBlock.Text).ToCollectionAsync();

            if (matches.Count == 0)
            {
                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();

                    Game match0 = new Game {
                        TeamOneScore = 0, TeamTwoScore = 0, TeamOneId = teamsIds[0], TeamTwoId = teamsIds[3], Ended = false,
                        TournamentId = TournamentIdTextBlock.Text, Nr = 1
                    };
                    await matchesTable.InsertAsync(match0);

                    Game match1 = new Game {
                        TeamOneScore = 0, TeamTwoScore = 0, TeamOneId = teamsIds[1], TeamTwoId = teamsIds[2], Ended = false,
                        TournamentId = TournamentIdTextBlock.Text, Nr = 2
                    };
                    await matchesTable.InsertAsync(match1);

                    Game match2 = new Game {
                        TeamOneScore = 0, TeamTwoScore = 0, TeamOneId = teamsIds[3], TeamTwoId = teamsIds[2], Ended = false,
                        TournamentId = TournamentIdTextBlock.Text, Nr = 3
                    };
                    await matchesTable.InsertAsync(match2);

                    Game match3 = new Game {
                        TeamOneScore = 0, TeamTwoScore = 0, TeamOneId = teamsIds[0], TeamTwoId = teamsIds[1], Ended = false,
                        TournamentId = TournamentIdTextBlock.Text, Nr = 4
                    };
                    await matchesTable.InsertAsync(match3);

                    Game match4 = new Game {
                        TeamOneScore = 0, TeamTwoScore = 0, TeamOneId = teamsIds[1], TeamTwoId = teamsIds[3], Ended = false,
                        TournamentId = TournamentIdTextBlock.Text, Nr = 5
                    };
                    await matchesTable.InsertAsync(match4);

                    Game match5 = new Game {
                        TeamOneScore = 0, TeamTwoScore = 0, TeamOneId = teamsIds[2], TeamTwoId = teamsIds[0], Ended = false,
                        TournamentId = TournamentIdTextBlock.Text, Nr = 6
                    };
                    await matchesTable.InsertAsync(match5);
                }
            }
        }
        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 void AssignTeamButton_Click(object sender, RoutedEventArgs e)
        {
            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)
            {
                var    selectedItem = TeamsListComboBox.SelectedItem;
                var    team         = selectedItem as Team;
                string teamId       = team.Id;

                await InsertTournamentTeam(teamId);
                await RefreshTeams();
                await RefreshComboBoxTeams();
            }
            else
            {
                await new MessageDialog("Za dużo drużyn w turnieju.").ShowAsync();
            }
        }
        private async Task RefreshComboBoxTeams()
        {
            MobileServiceInvalidOperationException exception = null;

            try
            {
                // This code refreshes the entries in the list view by querying the TodoItems table.
                // The query excludes completed TodoItems

                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();
                }
                else
                {
                    teams = await teamsTable.ToCollectionAsync();
                }
            }
            catch (MobileServiceInvalidOperationException e)
            {
                exception = e;
            }

            if (exception != null)
            {
                await new MessageDialog(exception.Message, "Error loading teams").ShowAsync();
            }
            else
            {
                TeamsListComboBox.ItemsSource   = teams;
                this.AssignTeamButton.IsEnabled = true;
            }
        }
Esempio n. 6
0
        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;
            }
        }