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

            //tournament is complete;
            CompleteTournament(model);

            return(output - 1);
        }
 /// <summary>
 /// function job is to find the advance winner and place to next round.
 /// </summary>
 /// <param name="models"></param>
 /// <param name="tournament"></param>
 private static void AdvanceWinners(List <MatchupModel> models, TournamentModel tournament)
 {
     foreach (MatchupModel m in models)
     {
         foreach (List <MatchupModel> round in tournament.Rounds)
         {
             foreach (MatchupModel rm in round)
             {
                 foreach (MatchupEntryModel me in rm.Entries)
                 {
                     if (me.ParentMatchup != null)
                     {
                         if (me.ParentMatchup.Id == m.Id)
                         {
                             me.TeamCompeting = m.Winner;
                             GlobalConfig.Connection.UpdateMatchup(rm);
                         }
                     }
                 }
             }
         }
     }
 }
        private static void CompleteTournament(TournamentModel model)
        {
            GlobalConfig.Connection.CompleteTournament(model);
            TeamModel winners  = model.Rounds.Last().First().Winner;
            TeamModel runnerup = model.Rounds.Last().First().Entries.Where(x => x.TeamCompeting != winners).First().TeamCompeting;

            decimal winnerPrize   = 0;
            decimal runnerUpPrize = 0;

            if (model.Prizes.Count > 0)
            {
                decimal totalIncome = model.EnteredTeams.Count * model.EntryFee;

                PrizeModel firstPlacePrize  = model.Prizes.Where(x => x.PlaceNumber == 1).FirstOrDefault();
                PrizeModel secondPlacePrize = model.Prizes.Where(x => x.PlaceNumber == 2).FirstOrDefault();

                if (firstPlacePrize != null)
                {
                    winnerPrize = firstPlacePrize.CalculatePrizePayout(totalIncome);
                }

                if (secondPlacePrize != null)
                {
                    runnerUpPrize = secondPlacePrize.CalculatePrizePayout(totalIncome);
                }
            }

            //send email to all tournament

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


            subject = $"In { model.TournamentName }, { winners.TeamName } has won!";

            body.AppendLine("<h1> We have a WINNER!</h1>");
            body.AppendLine("<p>Congratulations to our winner on a great tournament.</p>");
            body.AppendLine("<br / > ");
            if (winnerPrize > 0)
            {
                body.AppendLine($"<p>{winners.TeamName } will receive ${winnerPrize }</p>");
            }
            if (runnerUpPrize > 0)
            {
                body.AppendLine($"<p>{runnerup.TeamName } will receive ${ runnerUpPrize }</p>");
            }
            body.AppendLine("<p>Thanks for a great tournament everyone.</p>");
            body.AppendLine("~Tournament Tracker");

            List <string> bcc = new List <string>();

            foreach (TeamModel t in model.EnteredTeams)
            {
                foreach (PersonModel p in t.TeamMembers)
                {
                    if (p.EmailAddress.Length > 0)
                    {
                        bcc.Add(p.EmailAddress);
                    }
                }
            }

            EmailLogic.SendEmail(new List <string>(), bcc, subject, body.ToString());

            //complete tournament
            model.CompleteTournament();
        }
Esempio n. 4
0
        private static void CompleteTournament(TournamentModel model)
        {
            GlobalConfig.Connection.CompleteTournament(model);
            TeamModel winners = model.Rounds.Last().First().Winner;
            TeamModel looser  = model.Rounds.Last().First().Entries.Where(x => x.TeamCompeting != winners).First().TeamCompeting;

            decimal winnerPrize = 0;
            decimal looserPrize = 0;

            if (model.Prizes.Count > 0)
            {
                decimal totalIncome = model.teamModels.Count * model.EntryFee;

                PrizeModel firstPlacePrize  = model.Prizes.Where(x => x.PlaceNumber == 1).FirstOrDefault();
                PrizeModel secondPlacePrize = model.Prizes.Where(x => x.PlaceNumber == 2).FirstOrDefault();

                if (firstPlacePrize != null)
                {
                    winnerPrize = firstPlacePrize.CalculatePrrizePayout(totalIncome);
                }
                if (secondPlacePrize != null)
                {
                    looserPrize = secondPlacePrize.CalculatePrrizePayout(totalIncome);
                }
            }

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

            subject = $"In {model.TournamentName} , {winners.TeamName} has won";

            body.AppendLine("<h1>We have a winner!</h1/");
            body.AppendLine($"Congratulations!");
            body.AppendLine("<br/>)");

            if (winnerPrize > 0)
            {
                body.AppendLine($"{winners.TeamName} will recive ${winnerPrize}");
            }
            if (looserPrize > 0)
            {
                body.AppendLine($"{looser.TeamName} will recive ${looserPrize}");
            }
            body.AppendLine("Have a great time!");
            body.AppendLine("~Tournament Tracke");

            List <string> bcc = new List <string>();

            foreach (TeamModel team in model.teamModels)
            {
                foreach (PersonModel person in team.TeamMembers)
                {
                    bcc.Add(person.EmailAddress);
                }
            }

            EmailLogic.SendEmail(new List <string> {
            }, bcc, subject, body.ToString());

            model.CompleteTournament();
        }