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;
            }

            // Create tournament model
            TournamentModel tm = new TournamentModel();

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

            tm.Prizes       = selectedPrizes;
            tm.EnteredTeams = selectedTeams;

            TournamentLogic.CreateRounds(tm);

            // Create tournament entry
            // Create prizes entry
            // create all of the team entry
            GlobalConfig.Connection.CreateTournament(tm);

            tm.AlertToNewRound();

            TournamentViewerForm frm = new TournamentViewerForm(tm);

            frm.Show();
            this.Close();
        }
        /// <summary>
        /// Updates the tournament.
        /// </summary>
        /// <param name="model">Tournament to update.</param>
        public static void UpdateTournamentResults(TournamentModel model)
        {
            int currentTournamentRound = model.CheckCurrentRound();

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

            foreach (List <MatchupModel> round in model.Rounds)
            {
                foreach (MatchupModel rm in round)
                {
                    if (rm.Winner == null && (rm.Entries.Any(x => x.Score != 0) || rm.Entries.Count == 1))
                    {
                        toScore.Add(rm);
                    }
                }
            }

            TournamentLogic.ScoreMatchups(toScore);

            TournamentLogic.AdvanceWinners(toScore, model);

            toScore.ForEach(x => GlobalConfig.Connection.UpdateMatchup(x));

            int endingRound = model.CheckCurrentRound();

            if (endingRound > currentTournamentRound)
            {
                TournamentLogic.AlertUsersInNewRounds(model);
            }
        }
        /// <summary>
        /// Tournament to complete.
        /// </summary>
        /// <param name="model">Tournament to complete.</param>
        public void CompleteTournament(TournamentModel model)
        {
            List <TournamentModel> tournament = GlobalConfig.TournamentFile.FullFilePath().LoadFile().ConvertToTournamentModel();

            tournament.Remove(model);

            tournament.SaveToTournamentFile();

            TournamentLogic.UpdateTournamentResults(model);
        }
        /// <summary>
        /// Creates a tournament.
        /// </summary>
        /// <param name="model">Model of the tournament.</param>
        public void CreateTournament(TournamentModel model)
        {
            List <TournamentModel> tournament = GlobalConfig.TournamentFile.FullFilePath().LoadFile().ConvertToTournamentModel();

            int currentId = 1;

            if (tournament.Count > 0)
            {
                currentId = currentId = tournament.OrderByDescending(x => x.Id).First().Id + 1;
            }

            model.Id = currentId;

            model.SaveRoundsToFile();

            tournament.Add(model);

            tournament.SaveToTournamentFile();

            TournamentLogic.UpdateTournamentResults(model);
        }
Example #5
0
        /// <summary>
        /// Creates a new tournament.
        /// </summary>
        /// <param name="model">Model of the tournament.</param>
        public void CreateTournament(TournamentModel model)
        {
            // Connect to the database.
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(Db)))
            {
                // Save the tournament data.
                this.SaveTournament(connection, model);

                // Save the prize data for this tournament.
                this.SaveTournamentPrizes(connection, model);

                // Save the entries data for this tournament.
                this.SaveTournamentEntries(connection, model);

                // Save the rounds data for this tournament.
                this.SaveTournamentRounds(connection, model);

                // Used to update the tournament (mainly for bye weeks).
                TournamentLogic.UpdateTournamentResults(model);
            }
        }
        /// <summary>
        /// Determines the round.
        /// </summary>
        /// <param name="model">Tournament to check for rounds.</param>
        /// <returns>Round number.</returns>
        private static int CheckCurrentRound(this TournamentModel model)
        {
            int output = 1;

            foreach (List <MatchupModel> round in model.Rounds)
            {
                if (round.All(x => x.Winner != null))
                {
                    output += 1;
                }
                else
                {
                    return(output);
                }
            }


            // If else condition in not hit, the tournament is complete
            TournamentLogic.CompleteTournament(model);

            return(output - 1);
        }