private static void AlterPersonToNewRound(PersonModel p, string teamName, MatchupEntryModel competitor)
        {
            // To validate email you can use regular Expression or regex
            if (p.EmailAddress.Length == 0)
            {
                // if there is no Email, then we dont do anything.
                return;
            }

            string        to      = "";
            string        subject = "";
            StringBuilder body    = new StringBuilder();

            if (competitor != null)
            {
                subject = $"You have a new matchup with { competitor.TeamCompeting.TeamName }";

                body.AppendLine("<h1>You have a new matchup</h1>");
                body.Append("<strong>Competitor: </strong>");
                body.Append(competitor.TeamCompeting.TeamName);
                body.AppendLine();
                body.AppendLine();
                body.AppendLine("Have a great time!");
                body.AppendLine("~ Tournament Tracker");
            }
            else
            {
                subject = "You have a bye week this round";
                body.AppendLine("Enjoy your rond off!");
                body.AppendLine("~ Tournament Tracker");
            }

            to = p.EmailAddress;


            EmailLogic.SendEmail(to, subject, body.ToString());
        }
Exemple #2
0
        private static void AlertPersonToNewRound(PersonModel p, string teamName, MatchupEntryModel competitor)
        {
            if (p.EmailAddress.Length == 0)
            {
                return;
            }

            string to      = "";
            string subject = "";

            StringBuilder body = new StringBuilder();

            if (competitor != null)
            {
                subject = $"You have a new matchup with {competitor.TeamCompeting.TeamName}";

                body.Append("<h1>You have a new matchup</h1>");
                body.Append("<strong>Competitor: </strong>");
                body.Append(competitor.TeamCompeting.TeamName);
                body.AppendLine();
                body.AppendLine();
                body.AppendLine();
                body.AppendLine("Have a great time!");
                body.AppendLine("~Tournament Tracker");
            }
            else
            {
                subject = "You have a bye in this round";
                body.AppendLine("Enjoy your round off!");
                body.AppendLine("~Tournament Tracker");
            }

            to = p.EmailAddress;


            EmailLogic.SendEmail(to, subject, body.ToString());
        }
        private static void AlertPersonToNewRound(PersonModel p, string teamName, MatchupEntryModel competitor)
        {
            if (p.EmailAddress.Length == 0)
            {
                return;
            }

            //string fromAddress = "";
            string to      = ""; //We can send the message more than to one person
            string subject = "";
            //string body = "";
            StringBuilder body = new StringBuilder(); //Соединение строк.

            if (competitor != null)
            {
                subject = $"You have a new matchup with { competitor.TeamCompeting.TeamName }";

                body.AppendLine("<h1>You have a new matchup</h1>");
                body.Append("<strong>Competitor: ");
                body.Append(competitor.TeamCompeting.TeamName);
                body.AppendLine();
                body.AppendLine();
                body.AppendLine("Have a great time!");
                body.AppendLine("~Tournament Tracker");
            }
            else
            {
                subject = "You have a bye week this round";

                body.AppendLine("Enjoy your round off!");
                body.AppendLine("~Tournament Tracker");
            }

            to = p.EmailAddress;

            EmailLogic.SendEmail(to, subject, body.ToString());
        }
        private static void AlertPlayerToNewRound(PersonModel player, string teamName, MatchupEntryModel competingTeam)
        {
            if (player.EmailAddress.Length > 0)
            {
                string        to      = "";
                string        subject = "";
                StringBuilder body    = new StringBuilder();

                if (competingTeam != null)
                {
                    subject = $"You have a new game with { competingTeam.TeamCompeting.TeamName }!";
                    body.AppendLine("<h1>You have a new game ahead</h1>");
                    body.Append("<strong>Competitor: </strong>");
                    body.Append(competingTeam.TeamCompeting.TeamName);
                    body.AppendLine();
                    body.AppendLine();
                    body.AppendLine("Best of luck!");
                    body.AppendLine("~ Tournament Tracker");
                }
                else
                {
                    subject = "You have a bye week this round";
                    body.AppendLine("Rest up this week and prepare!");
                    body.AppendLine("~ Tournament Tracker");
                }

                to = player.EmailAddress;

                EmailLogic.SendEmail(to, subject, body.ToString());
            }

            if (player.CellPhoneNumber.Length > 0)
            {
                if (competingTeam != null)
                {
                    SMSLogic.SendSMSMessage(player.CellPhoneNumber, $"You have a new matchup with { competingTeam.TeamCompeting.TeamName }");
                }
                else
                {
                    SMSLogic.SendSMSMessage(player.CellPhoneNumber, "You have a bye week this round");
                }
            }
        }
Exemple #5
0
        public static List <List <MatchupModel> > CreateRounds(TournamentModel model)
        {
            // Get randomized list of teams
            List <TeamModel> randomizedTeams = model.EnteredTeams.OrderBy(x => Guid.NewGuid()).ToList();

            // Get number of rounds
            int rounds = (int)(Math.Ceiling(Math.Log((double)randomizedTeams.Count, 2)));

            // Get number of byes required
            int byes = (int)(Math.Pow(2, (double)(rounds - 1)) - randomizedTeams.Count);

            int matchups = (int)(Math.Pow(2, (double)rounds) - 1);

            int lastroundMatchupCountBuffer = 0;
            int lastroundMatchupCount       = 0;
            int lastRoundMatchupListInd     = 0;
            int randomTeamIndex             = 0;

            bool endOfList = false;

            List <List <MatchupModel> > matchupModelsAllRounds = new List <List <MatchupModel> >();
            List <MatchupModel>         lastRoundMatchupList   = new List <MatchupModel>();

            // Start creating matchups
            for (int i = 0; i < rounds; i++)
            {
                List <MatchupModel> matchupModelsPerRound = new List <MatchupModel>();

                if (i + 1 == 1)
                {
                    for (int j = 0; j < (int)Math.Ceiling((double)randomizedTeams.Count / 2); j++)
                    {
                        // Create new MatchupModel
                        MatchupModel matchupModel = new MatchupModel();
                        matchupModel.MatchupRound = i + 1;
                        matchupModel.TournamentId = model.Id;

                        // Add in DB and get id
                        matchupModel = GlobalConfig.Connection.CreateMatchup(matchupModel);

                        for (int k = 0; k < 2; k++)//Add two teams per Matchup
                        {
                            if (endOfList)
                            {
                                // Add byes to Matchups
                                MatchupEntryModel matchupEntryModel = new MatchupEntryModel();
                                // Add null teams to matchups with bye
                                matchupEntryModel.MatchupId    = matchupModel.Id;
                                matchupEntryModel.TournamentId = model.Id;

                                GlobalConfig.Connection.CreateMatchupEntry(matchupEntryModel);

                                matchupModel.Entries.Add(matchupEntryModel);
                            }
                            else
                            {
                                //  Create MatchupEntry
                                MatchupEntryModel matchupEntryModel = new MatchupEntryModel();
                                //  Add teams to first round Matchups
                                matchupEntryModel.MatchupId     = matchupModel.Id;
                                matchupEntryModel.TournamentId  = model.Id;
                                matchupEntryModel.TeamCompeting = randomizedTeams[randomTeamIndex];

                                GlobalConfig.Connection.CreateMatchupEntry(matchupEntryModel);

                                matchupModel.Entries.Add(matchupEntryModel);

                                if (randomizedTeams[randomTeamIndex] == randomizedTeams.Last())
                                {
                                    endOfList = true;
                                }
                                randomTeamIndex += 1;
                            }
                        }
                        lastroundMatchupCountBuffer += 1;
                        matchupModelsPerRound.Add(matchupModel);
                    }
                }
                else
                {
                    for (int j = 0; j < lastroundMatchupCount / 2; j++)
                    {
                        // Create new MatchupModel
                        MatchupModel matchupModel = new MatchupModel();
                        matchupModel.MatchupRound = i + 1;
                        matchupModel.TournamentId = model.Id;

                        // Add in DB and get id
                        matchupModel = GlobalConfig.Connection.CreateMatchup(matchupModel);

                        for (int k = 0; k < 2; k++)
                        {
                            //  Create blank MatchupEntries
                            MatchupEntryModel matchupEntryModel = new MatchupEntryModel();
                            matchupEntryModel.MatchupId     = matchupModel.Id;
                            matchupEntryModel.TournamentId  = model.Id;
                            matchupEntryModel.ParentMatchup = lastRoundMatchupList[lastRoundMatchupListInd];

                            GlobalConfig.Connection.CreateMatchupEntry(matchupEntryModel);

                            matchupModel.Entries.Add(matchupEntryModel);
                            lastRoundMatchupListInd += 1;
                        }
                        lastroundMatchupCountBuffer += 1;
                        matchupModelsPerRound.Add(matchupModel);
                    }
                }
                matchupModelsAllRounds.Add(matchupModelsPerRound);
                lastroundMatchupCount = lastroundMatchupCountBuffer;
                lastRoundMatchupList  = matchupModelsPerRound;
            }
            return(matchupModelsAllRounds);
        }
        private static void AlertPersonToNewRound(PersonModel person, string teamName, MatchupEntryModel competitor)
        {
            if (person.EmailAddress.Length > 0)
            {
                string to      = "";
                string subject = "";

                StringBuilder body = new StringBuilder();

                if (competitor != null)
                {
                    subject = $"You have a new matchup with { competitor.TeamCompeting.TeamName }";

                    body.AppendLine("<h1>You have a new matchup</h1>");
                    body.Append("<strong>Competitor: </strong>");
                    body.Append(competitor.TeamCompeting.TeamName);
                    body.AppendLine();
                    body.AppendLine();
                    body.AppendLine("Have an enjoyable match");
                    body.AppendLine("~ Tournament Tracker ~");
                }
                else
                {
                    subject = "You have a bye week this round.";

                    body.AppendLine("Thank You, enjoy your round off");
                    body.AppendLine("~ Tournament Tracker ~");
                }


                to = person.EmailAddress;

                EmailLogic.SendEmail(to, subject, body.ToString());
            }

            if (person.CellphoneNumber.Length > 0)
            {
                TextingLogic.SendSMSMessage(person.CellphoneNumber, $"You have a new matchup with { competitor.TeamCompeting.TeamName }");
            }
        }
        private static void AlertPersonToNewRound(PersonModel person, string teamName, MatchupEntryModel competitor)
        {
            if (person.EmailAddress.Length == 0)
            {
                return;
            }
            List <string> to      = new List <string>();
            string        subject = "";

            StringBuilder body = new StringBuilder();

            if (competitor != null)
            {
                subject = $"You have a new matchup with { competitor.TeamCompeting.TeamName }.";


                body.AppendLine("<h1>You have a new matchup.</h1>");
                body.AppendLine($"<strong>Competitor: {competitor.TeamCompeting.TeamName}</strong>");

                body.AppendLine("Have a great time");
                body.AppendLine("~Tournament Tracker");
            }
            else
            {
                subject = "You have a bye week this round.";
                body.AppendLine("Enjoy your round off");
                body.AppendLine("~Tournament Tracker");
            }

            to.Add(person.EmailAddress);


            EmailLogic.SendEmail(new List <string>(), to, subject, body.ToString());
        }
        /// <summary>
        /// Alerts person of the new round.
        /// </summary>
        /// <param name="person">Person to alert.</param>
        /// <param name="teamName">Team they're on.</param>
        /// <param name="matchupEntryModel">New Matchup to be played.</param>
        private static void AlertPersonToNewRound(PersonModel person, string teamName, MatchupEntryModel matchupEntryModel)
        {
            if (person.EmailAddress.Length == 0)
            {
                return;
            }

            string to      = "";
            string subject = "";

            StringBuilder sb = new StringBuilder();

            if (matchupEntryModel != null)
            {
                subject = $"You have a new matchup with { matchupEntryModel.TeamCompeting.TeamName }";
                sb.AppendLine("<h1>You have a new matchup!</h1>");
                sb.Append("<strong>Competitor: </strong>");
                sb.Append(matchupEntryModel.TeamCompeting.TeamName);
                sb.Append("");
                sb.Append("");
                sb.AppendLine(", May the best team win!");
                sb.AppendLine("~ Tournament Tracker / SM");
            }
            else
            {
                subject = "You have a bye week this round";
                sb.Append("Enjoy your round off.");
                sb.AppendLine("~ Tournament Tracker / SM");
            }

            to = person.EmailAddress;

            Email.SendEmail(to, subject, sb.ToString());
        }