Пример #1
0
        private void WireUpTournamentOrder()
        {
            if (finishedTournament.IsLeague)
            {
                List <LeagueParticipantModel> leagueParticipants = SqlDataHandler.GetLeagueParticipantsForDisplay(finishedTournament.Id);
                _champion = new TeamModel(leagueParticipants.First().TeamName);
                _runnerUp = new TeamModel(leagueParticipants[1].TeamName);
                _thirdPlaced.Add(new TeamModel(leagueParticipants[2].TeamName));
            }
            else
            {
                RoundModel       finalRound   = finishedTournament.Rounds.Last();
                List <TeamModel> roundWinners = SqlDataHandler.GetRoundWinners(finalRound.Id);

                _champion = roundWinners.First();
                _runnerUp = new TeamModel(finalRound.Games[0].Competitors.Find(team => team.CupRoundWinner == false).TeamName);



                RoundModel                  secondToLastRound = finishedTournament.Rounds[finalRound.RoundNumber - 2];
                List <GameModel>            semiFinalGames    = SqlDataHandler.GetGamesByRound(secondToLastRound);
                List <GameParticipantModel> semiFinalLosers   = new List <GameParticipantModel>();

                foreach (GameModel game in semiFinalGames)
                {
                    semiFinalLosers.Add(game.Competitors.Find(team => team.CupRoundWinner == false));
                }

                _thirdPlaced.Add(new TeamModel(semiFinalLosers[0].TeamName));
                _thirdPlaced.Add(new TeamModel(semiFinalLosers[1].TeamName));
            }
        }
        public void EnterResult()
        {
            HomeTeam.Score = int.Parse(HomeScore);
            AwayTeam.Score = int.Parse(AwayScore);

            tournamentView.SelectedGame.Unplayed = false;

            SqlDataHandler.UpdateGameScoreAndStatus(tournamentView.SelectedGame);

            if (tournamentView.CurrentTournament.IsLeague)
            {
                SqlDataHandler.UpdateLeagueParticipants(tournamentView.CurrentTournament, tournamentView.SelectedGame);
            }
            else
            {
                SqlDataHandler.UpdateGameParticipantAsCupRoundWinner(tournamentView.SelectedGame);

                if (RoundComplete())
                {
                    int currentRoundIndex = tournamentView.SelectedRound.RoundNumber - 1;

                    List <TeamModel> nextRoundParticipants = SqlDataHandler.GetRoundWinners(tournamentView.SelectedRound.Id);

                    if (tournamentView.SelectedRound.RoundNumber < tournamentView.RoundList.Count)
                    {
                        RoundModel nextRound = tournamentView.CurrentTournament.Rounds[currentRoundIndex + 1];

                        RoundLogic.CreateCupRoundGames(nextRoundParticipants, nextRound);
                    }
                }
            }

            if (TournamentComplete())
            {
                tournamentView.CurrentTournament.Finished = true;
                SqlDataHandler.UpdateTournamentStatus(tournamentView.CurrentTournament);
            }

            tournamentView.CanEnterResult = false;
            tournamentView.GameList.Refresh();

            TryClose();
        }