public static void UpdateTournamentResult(TournamnetModel model)
        {
            int startingRound = model.CheckCurrentRound();

            List <MatchupModel> toScore = new List <MatchupModel>();

            foreach (List <MatchupModel> round in model.Rounds)
            {
                foreach (MatchupModel rm in round)
                {
                    //check if (any of the entries has a score not 0, or entries =1 (thats means we have a bye team))
                    // and we don't have a winner
                    if (rm.Winner == null && (rm.Entries.Any(x => x.Score != 0) || rm.Entries.Count == 1))
                    {
                        toScore.Add(rm);
                    }
                }
            }

            MarkWinnerInMatchups(toScore);

            AdvanceWinners(toScore, model);


            toScore.ForEach(x => GlobalConfig.Connection.updateMatchup(x));
            int endingRound = model.CheckCurrentRound();

            if (endingRound > startingRound)
            {
                model.AlertUsersToNewRound();
            }
        }
Esempio n. 2
0
        private void createTournamentButton_Click(object sender, EventArgs e)
        {
            //Validate data
            decimal fee           = 0;
            bool    feeAcceptable = decimal.TryParse(entryFeeValue.Text, out fee);

            if (!feeAcceptable)
            {
                MessageBox.Show("You need to enter a valid Entry Fee.", "Invalid Fee",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // 1-Create our Tournament model
            TournamnetModel tm = new TournamnetModel();

            tm.TournamentName = tournamentNameValue.Text;
            tm.EntryFee       = fee;

            //foreach (PrizeModel prize in selectedPrizes)
            //{
            //    tm.Prizes.Add(prize);
            //}
            //instead of for loop
            tm.Prizes       = selectedPrizes;
            tm.EnteredTeams = selectedTeams;

            // 2-Create/wire up our matchups
            TournamentLogic.CreateRounds(tm);

            // 3-Create Tournament entry
            // 4-Create all the prizes entries
            // 5-Create all of team entries
            //the next line will do the previous three tasks
            GlobalConfig.Connection.CreateTournament(tm);

            tm.AlertUsersToNewRound();

            TournamentViewerForm frm = new TournamentViewerForm(tm);

            frm.Show();
            this.Close();
        }