Ejemplo n.º 1
0
        private static void AlertPersonToNewRound(Person person, string teamName, MatchupEntry competitor)
        {
            if (person.EmailAdress.Length == 0)
            {
                return;
            }

            string        toAdress = "";
            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("Have a great time!");
                body.AppendLine("~Tournament Tracker");
            }
            else
            {
                subject = "You have a bye week this round";
                body.AppendLine("Enjoy your week off!");
                body.AppendLine("~Tournament Tracker");
            }

            toAdress = person.EmailAdress;

            EmailLogic.SendEmail(toAdress, subject, body.ToString());
        }
        private static List <Team> GetTeamsByPlace(Tournament model)
        {
            List <Team>            output = new List <Team>();
            Dictionary <Team, int> teamsBonusPointsDict = new Dictionary <Team, int>();

            foreach (Team t in model.EnteredTeams)
            {
                teamsBonusPointsDict.Add(t, 0);
            }

            Matchup finalMatch = model.Rounds.Last().First();

            output.Add(finalMatch.Winner);

            for (int roundIndex = model.Rounds.Count - 1; roundIndex >= 0; roundIndex--)
            {
                int         counter    = model.Rounds.Count - roundIndex - 1;
                int         bonusScore = (int)Math.Pow(2, counter);
                List <Team> teamsLost  = new List <Team>();
                foreach (Matchup match in model.Rounds[roundIndex])
                {
                    Team matchLoser = match.Entries.Find(me => me.TeamCompeting != match.Winner)?.TeamCompeting;
                    if (matchLoser != null)
                    {
                        teamsLost.Add(matchLoser);
                    }
                    MatchupEntry winnerEntry = match.Entries.Find(m => m.TeamCompeting == match.Winner);
                    ScoreBonusPointsToPreviousMatchups(teamsBonusPointsDict, winnerEntry, bonusScore);
                }

                Dictionary <Team, int> teamsPointsInRound = new Dictionary <Team, int>();
                foreach (Team t in teamsLost)
                {
                    teamsPointsInRound.Add(t, teamsBonusPointsDict[t]);
                }
                teamsPointsInRound.OrderByDescending(t => t.Value);

                while (teamsPointsInRound.Count > 0)
                {
                    Team bestOfLostTeams = teamsPointsInRound.First().Key;
                    output.Add(bestOfLostTeams);
                    teamsPointsInRound.Remove(bestOfLostTeams);
                }
            }
            return(output);
        }
        private static void AlertPersonToNewRound(Person p, string teamName, MatchupEntry matchupEntry)
        {
            if (p.EmailAddress.Length == 0)
            {
                return;
            }

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

            if (matchupEntry != null)
            {
                subject = $"You have matchup with { matchupEntry.TeamCompeting.TeamName }.";
                body.AppendLine("<h1>You have new matchup!</h1>");
                body.AppendLine("<strong>Competitor:");
                body.AppendLine(matchupEntry.TeamCompeting.TeamName);
                body.AppendLine();
                body.AppendLine();
                body.AppendLine("See you soon!");
                body.AppendLine("~Tournament Tracker");
            }
            else
            {
                subject = $"You have buy in this round.";
                body.AppendLine("<h1>You have a buy round this time!</h1>");
                body.AppendLine();
                body.AppendLine();
                body.AppendLine("See you in next round!");
                body.AppendLine("~Tournament Tracker");
            }
            to = p.EmailAddress;


            EmailLogic.SendEmail(to, subject, body.ToString());
        }
        private static void ScoreBonusPointsToPreviousMatchups(Dictionary <Team, int> teamsBonusPoints, MatchupEntry entry, int score)
        {
            int  teamScore = 0;
            bool success   = teamsBonusPoints.TryGetValue(entry.TeamCompeting, out teamScore);

            if (success)
            {
                teamsBonusPoints[entry.TeamCompeting] += score;
            }

            if (entry.ParentMatchup != null)
            {
                foreach (MatchupEntry me in entry.ParentMatchup.Entries)
                {
                    ScoreBonusPointsToPreviousMatchups(teamsBonusPoints, me, score);
                }
            }
        }