예제 #1
0
        private static void CompleteTournament(TournamentModel model)
        {
            GlobalConfig.Connection.CompleteTournament(model);

            TeamModel winner   = model.Rounds.Last().First().Winner;
            TeamModel runnerUp = model.Rounds.Last().First().Entries.Where(x => x.TeamCompeting != winner).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
            model.AlertUsersToCompletedTournament(winner, runnerUp, winnerPrize, runnerUpPrize);

            // complete tournament
            model.CompleteTournament();
        }
        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("<p>  Congratulations to our winner on a great tournament </p>");
            body.AppendLine("<string> Competitor: </strong>");
            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("~TournamentTracker");

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

            model.CompleteTournament();
        }
예제 #3
0
        private static void CompleteTournament(TournamentModel tournament)
        {
            GlobalConfig.Connections.CompleteTournament(tournament);

            // Announce tournament results and prize distributions
            MatchupModel lastMatchup = tournament.Rounds.Last().First();
            TeamModel    winner      = lastMatchup.Winner;
            TeamModel    runnerUp    = lastMatchup.Entries.Where(x => x.TeamCompeting != winner).First().TeamCompeting;
            string       subject     = $"{tournament.TournamentName} has concluded!";

            StringBuilder body = new StringBuilder();

            body.AppendLine("<h2>WE HAVE A WINNER!</h2>");
            body.AppendLine($"<p>Congratulations to <b>{winner.TeamName}</b> on a great tournament.</p>");
            body.AppendLine("<br>");

            if (tournament.Prizes.Count > 0)
            {
                decimal    totalIncome      = tournament.EnteredTeams.Count * tournament.EntryFee;
                PrizeModel firstPlacePrize  = tournament.Prizes.Where(x => x.PlaceNumber == 1).FirstOrDefault();
                PrizeModel secondPlacePrize = tournament.Prizes.Where(x => x.PlaceNumber == 2).FirstOrDefault();

                if (firstPlacePrize != null)
                {
                    decimal winnerPrizeAmt = CalculatePayout(firstPlacePrize, totalIncome);
                    body.AppendLine($"<p>{winner.TeamName} will receive ${string.Format("{0:0.00}", winnerPrizeAmt)}!</p>");
                }

                if (secondPlacePrize != null)
                {
                    decimal runnerUpPrizeAmt = CalculatePayout(secondPlacePrize, totalIncome);
                    body.AppendLine($"<p>{runnerUp.TeamName} will receive ${string.Format("{0:0.00}", runnerUpPrizeAmt)}.</p>");
                }

                if (firstPlacePrize != null || secondPlacePrize != null)
                {
                    body.AppendLine("<br>");
                }
            }

            body.AppendLine("<p>Hope everyone had a great time.</p>");
            body.AppendLine("<p>~Tournament Tracker</p>");

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

            foreach (TeamModel t in tournament.EnteredTeams)
            {
                foreach (PersonModel player in t.TeamMembers)
                {
                    bcc.Add(player.Email);
                }
            }

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

            // Complete tournament
            tournament.CompleteTournament();
        }
예제 #4
0
        /// <summary>
        /// Complete the tournament with the message the prizes, that winners won
        /// </summary>
        /// <param name="model"></param>
        private static void CompleteTournament(TournamentModel model)
        {
            GlobalConfig.Connection.CompleteTournament(model);
            TeamModel winner = model.Rounds.Last().First().Winner;
            TeamModel looser = model.Rounds.Last().First().Entries.Where(x => x.TeamCompeting != winner).First().TeamCompeting;

            decimal winnerPrize = 0;
            decimal looserPrize = 0;

            if (model.Prizes.Count > 0)
            {
                decimal totalIncome = model.Teams.Count * model.EntryFee;
                foreach (PrizeModel prize in model.Prizes)
                {
                    if (prize.PlaceNumber == 1)
                    {
                        if (prize.PrizeAmount != 0)
                        {
                            winnerPrize = prize.PrizeAmount;
                        }
                        else
                        {
                            winnerPrize = Decimal.Multiply(totalIncome, Convert.ToDecimal(prize.PrizePercentage / 100));
                        }
                    }
                    else if (prize.PlaceNumber == 2)
                    {
                        if (prize.PrizeAmount != 0)
                        {
                            looserPrize = prize.PrizeAmount;
                        }
                        else
                        {
                            looserPrize = Decimal.Multiply(totalIncome, Convert.ToDecimal(prize.PrizePercentage / 100));
                        }
                    }
                }
            }

            string finalMessage = $"Congratulations for the {winner.TeamName} team";

            if (winnerPrize > 0)
            {
                finalMessage += $", the {winner.TeamName} team won {winnerPrize}$";
            }
            if (looserPrize > 0)
            {
                finalMessage += $", the {looser.TeamName} team won {looserPrize}$";
            }

            finalMessage += " ! Tournament completed !";

            model.CompleteTournament(finalMessage);
        }
        public static void UpdateTournamentRound(this TournamentModel tournament, RoundModel round)
        {
            bool roundCompleted = round.Matchups.All(m => m.Winner != null);

            if (!roundCompleted)
            {
                throw new Exception("Winners have not been assigned to matchups in this round");
            }

            round.Active = false;

            GlobalConfig.Connection.UpdateRound(round);

            bool isFinalRound = tournament.Rounds.Count == round.Number;

            if (!isFinalRound)
            {
                RoundModel nextRound = tournament.Rounds.First(r => r.Number == round.Number + 1);

                nextRound.Active = true;

                nextRound.Matchups.ForEach(m => m.Entries.ForEach(me =>
                {
                    me.TeamCompeting = me.ParentMatchup.Winner;
                    GlobalConfig.Connection.UpdateMatchupEntry(me);
                }));

                GlobalConfig.Connection.UpdateRound(nextRound);

                tournament.NotifyEnteredTeams(nextRound);
            }
            else
            {
                tournament.CompleteTournament();
                tournament.NotifyTournamentComplete();
            }
        }
예제 #6
0
        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;
            // TODO: Limit the number of prizes to first and second
            // because third place is not easy to determine, probably use scores
            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 at completion of tournament with prize information
            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 \u20AC{ winnerPrize }</p>"); // The Euro sign hex code is u20AC
            }

            if (runnerUpPrize > 0)
            {
                body.AppendLine($"<p>{ runnerUp.TeamName } will receive \u20AC{ runnerUpPrize }</p>");
            }

            body.AppendLine("<p>Thanks for a great tournament everyone!</p>");
            body.AppendLine("<h2>~Tournament Tracker<h2/>");

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

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

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

            model.CompleteTournament();
        }
예제 #7
0
        private static void CompleteTournament(TournamentModel model)
        {
            model.IsActive = false;
            GlobalConfig.Connection.CompleteTournament(model);

            // find the max round from all the rounds
            var result = from sublist in model.Rounds
                         select new { myMax = sublist.Max(x => x.MatchupRound) };
            int myMax = result.Max(x => x.myMax);

            // Rounds is list of list.
            // Get the first list that contains the list of matchups where one of them has max round as round
            // get that first matchup of that matchup list (there will always be only one)
            TeamModel winner = model.Rounds.Where(x => x.First().MatchupRound == myMax)
                               .First().First().Winner;
            TeamModel runnerUp = model.Rounds.Where(x => x.First().MatchupRound == myMax)
                                 .First().First().Entries.Where(x => x.TeamCompeting != winner).First().TeamCompeting;

            decimal winnerAmount   = 0;
            decimal runnerUpAmount = 0;

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

                PrizeModel winnerPrize   = model.Prizes.Where(x => x.PlaceNumber == 1).FirstOrDefault();
                PrizeModel runnerUpPrize = model.Prizes.Where(x => x.PlaceNumber == 2).FirstOrDefault();

                if (winnerPrize != null)
                {
                    winnerAmount = winnerPrize.calculatePrizePayout(totalIncome);
                }

                if (runnerUpPrize != null)
                {
                    runnerUpAmount = runnerUpPrize.calculatePrizePayout(totalIncome);
                }
            }

            // Send email to all tournament
            string        subject = "";
            StringBuilder body    = new StringBuilder();


            subject = $"In {model.TournamentName}, {winner.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 (winnerAmount > 0)
            {
                body.AppendLine($"<p>{winner.TeamName} will recieve ${winnerAmount}.</p>");
            }

            if (runnerUpAmount > 0)
            {
                body.AppendLine($"<p>{runnerUp.TeamName} will recieve ${runnerUpAmount}.</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());

            model.CompleteTournament();
        }
        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);
                }
            }

            //Salje mail za kraj turnira
            string        subject = "";
            StringBuilder body    = new StringBuilder();

            subject = $"Turnir: { model.TournamentName } je osvojio tim: { winners.TeamName }";

            body.AppendLine("<h1>Imamo novog Pobjednika!</h1>");
            body.Append("<p>Pobjednik: </p>");
            body.AppendLine("<br />");

            if (winnerPrize > 0)
            {
                body.AppendLine($"<p> { winners.TeamName } sleduje nagrada u iznosu od: { winnerPrize } </p>");
                body.AppendLine();
            }

            if (runnerUpPrize > 0)
            {
                body.AppendLine($"<p> { runnerUp.TeamName } sleduje nagrada u iznosu od: { runnerUpPrize } </p>");
                body.AppendLine();
            }

            body.AppendLine();
            body.AppendLine("~ Organizator Turnira ~");

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

            //Zavrsi Turnir
            model.CompleteTournament();
        }
예제 #9
0
        private static void CompleteTournament(TournamentModel model)
        {
            GlobalConfig.Connections.CompleteTournament(model);
            var lastMatchup = model.Rounds.Last().First();

            var winner   = lastMatchup.Winner;
            var runnerUp = lastMatchup.Entries.Where(x => x.TeamCompeting != winner).First().TeamCompeting;

            decimal winnerPrize   = 0;
            decimal runnerUpPrize = 0;

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

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

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

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

            // Send Email to all teams
            var subject = "";
            var body    = new StringBuilder();

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

            body
            .AppendLine("<h1>We have a WINNER!</h1>")
            .AppendLine("<p>Congratulation to our winner on a great Tournament. </p>")
            .AppendLine("<br />");

            if (winnerPrize > 0)
            {
                body.AppendLine($"<p> { winner.TeamName } wil receive Rs:{ winnerPrize } </p>");
            }

            if (runnerUpPrize > 0)
            {
                body.AppendLine($"<p> { runnerUp.TeamName } wil receive Rs:{ runnerUpPrize } </p>");
            }
            body
            .AppendLine("Have a great time!")
            .AppendLine("Tournament Tracker... ");

            var bcc = new List <string>();

            foreach (var t in model.EnteredTeams)
            {
                foreach (var person in t.TeamMembers)
                {
                    if (person.EmailAddress.Length > 0)
                    {
                        bcc.Add(person.EmailAddress);
                    }
                }
            }

            EmailLogic.SendEmail(null, subject, body.ToString());

            //  Complete Tournament
            model.CompleteTournament();
        }
예제 #10
0
        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;

                List <PrizeModel> placePrizes = model.Prizes;

                if (placePrizes.Count > 0)
                {
                    foreach (PrizeModel prize in placePrizes)
                    {
                        winnerPrize += prize.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 Game");

            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();
        }
예제 #11
0
        public static void CompleteTournament(TournamentModel model)
        {
            GlobalConfig.Connection.CompleteTournament(model);

            // Last round only has 1 matchup and we find the winner for that matchup
            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.EntreredTeams.Count * model.EntryFee;

                // First of Default means if you don't find it then make it default empty for the object
                // type , in this case NULL if this was an int variable it would be 0
                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($"<pr> {winners.TeamName} will receive ${ winnerPrize }</p>");
            }

            if (runnerUpPrize > 0)
            {
                body.AppendLine($"<pr> {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.EntreredTeams)
            {
                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();
        }
        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);
                }
            }
            //Complete the tournament
            //string to = "";
            string subject = "";

            StringBuilder body = new StringBuilder();


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

            body.AppendLine("<h1>We have a Winner</h1>");
            body.AppendLine("<h6>Congratulations to the winners of this team</h6>");
            body.AppendLine(Environment.NewLine);

            if (winnerPrize > 0)
            {
                body.AppendLine($"{winners.TeamName} won this match and will recieve ${winnerPrize}");
            }

            if (runnerUpPrize > 0)
            {
                body.AppendLine($"{runnerUp.TeamName} is the runner up of this match and will recieve ${runnerUpPrize}");
            }
            body.AppendLine();
            body.AppendLine();
            body.AppendLine("Have an enjoyable match");
            body.AppendLine("~ Tournament Tracker ~");

            subject = "You have a bye week this round.";

            body.AppendLine("Thank You, for using out system");
            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());

            model.CompleteTournament();
        }
예제 #13
0
        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);
                }
            }


            // TODO - Change it to message box

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

            MessageBox.Show($"In { model.TournamentName }, { winners.TeamName } has won !!!" +
                            $"Congratulation to winner on a great tournament.");

            if (winnerPrize > 0)
            {
                MessageBox.Show($"{ winners.TeamName } will receive Rs{ winnerPrize }");
            }
            if (runnerUpPrize > 0)
            {
                MessageBox.Show($"{ runnerUp.TeamName } will receive Rs{ runnerUpPrize }");
            }

            //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());

            model.CompleteTournament();
        }
        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.EntryFee * model.EnteredTeams.Count;

                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);
                    prizeWinner = winnerPrize.ToString();
                }

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

            winnerTeam     = winners.TeamName;
            runnerUpTeam   = runnerUp.TeamName;
            tournamentName = model.TournamentName;

            // Emailing feature currently disabled.



            // Send email to all tournament participants.
            //string subject = "";
            //StringBuilder body = new StringBuilder();

            //subject = $"{ winners.TeamName } has won the { model.TournamentName } tournament!";

            //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 playing!</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();
        }
예제 #15
0
        /// <summary>
        /// Completes the tournament.
        /// </summary>
        /// <param name="model">Tournament to complete.</param>
        private static void CompleteTournament(TournamentModel model)
        {
            GlobalConfig.Connection.CompleteTournament(model);
            TeamModel winner   = model.Rounds.Last().First().Winner;
            TeamModel runnerUp = model.Rounds.Last().First().Entries.Where(x => x.TeamCompeting != winner).First().TeamCompeting;

            decimal winnerPrize   = 0;
            decimal runnerUpPrize = 0;

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

                PrizeModel firstPlace  = model.Prizes.Where(x => x.PlaceNumber == 1).FirstOrDefault();
                PrizeModel secondPlace = model.Prizes.Where(x => x.PlaceNumber == 2).FirstOrDefault();

                if (firstPlace != null)
                {
                    winnerPrize = firstPlace.DeterminePrizePayOut(totalPrizeAmount);
                }

                if (secondPlace != null)
                {
                    runnerUpPrize = secondPlace.DeterminePrizePayOut(totalPrizeAmount);
                }
            }

            // Send email to all tournament
            string subject = "";

            StringBuilder sb = new StringBuilder();

            subject = $"{model.TournamentName} has completed. {winner.TeamName} has won!";

            sb.AppendLine("<h1>WE HAVE A WINNER!</h1>");
            sb.AppendLine("<p>Congratulations to our winner on a great tournament.</p>");
            sb.AppendLine("<br />");

            if (winnerPrize > 0)
            {
                sb.AppendLine($"<p>{winner.TeamName} will recieve ${winnerPrize}</p>");
            }

            if (runnerUpPrize > 0)
            {
                sb.AppendLine($"<p>{runnerUp.TeamName} will recieve ${runnerUpPrize}</p>");
            }

            sb.AppendLine(", Thank you for competing!");
            sb.AppendLine("~ Tournament Tracker / SM");

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

            Email.SendEmail(new List <string>(), bcc, subject, sb.ToString());

            // Complete tournament.
            model.CompleteTournament();
        }
        private static void CompleteTournament(TournamentModel model)
        {
            TeamModel winners = model.Rounds.Last().First().Winner;
            //model.WinnerId = winners.Id;
            TeamModel runnerUp = model.Rounds.Last().First().Entries.Where(x => x.TeamCompeting != winners).First().TeamCompeting;

            model.DateFinished = DateTime.Now;
            model.Winner       = winners;

            GlobalConfig.Connection.CompleteTournament(model);

            decimal winnerPrize   = 0;
            decimal runnerUpPrize = 0;

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

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

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

            // Send email to all tournament.

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


            subject = $"In {model.TournamentName} {winners.TeamName} has won!";
            body.AppendLine("<h1>We have a WINNER!</h1>");
            body.Append("<P>Congratulations to our winner ou a great Tournament. </P>");
            body.AppendLine("<br/>");

            if (winnerPrize > 0)
            {
                body.AppendLine($"<p>The winnar {winners.TeamName} will receive ${winnerPrize}</p>");
            }
            if (runnerUpPrize > 0)
            {
                body.AppendLine($"<p>The runnerup {runnerUp.TeamName} will receive ${runnerUpPrize}</p>");
            }

            body.AppendLine("<p>Thanks for a great tournament!!</p>");
            body.AppendLine("~Tournament Tracker");

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

            foreach (TeamModel t in model.EnteredTeams)
            {
                foreach (PersonModel p in t.TeamMembers)
                {
                    if (!string.IsNullOrWhiteSpace(p.EmailAddress))
                    {
                        bcc.Add(p.EmailAddress);
                    }
                }
            }


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

            //Complete Tournament
            //model.DateFinished = DateTime.Now;
            //model.Winner = winners;
            model.CompleteTournament();
        }
        /// <summary>
        /// Complete Tournament by sending emails to everyone about winners and prizes they got.
        /// Currently we are handling prizes for only first 2 places
        /// </summary>
        /// <param name="tournament"></param>
        private static void CompleteTournament(TournamentModel tournament)
        {
            GlobalConfig.Connection.CompleteTournament(tournament);
            TeamModel winners = tournament.Rounds.Last().First().Winner;
            TeamModel loser   = tournament.Rounds.Last().First().Entries.Where(x => x.TeamCompeting != winners).First().TeamCompeting;

            decimal winnerPrize = 0;
            decimal loserPrize  = 0;

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

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

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

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

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

            body.AppendLine("<h1>We have a winner!</h1>");
            body.AppendLine("<p>Congratulations to our winner on the great tournament.</p>");
            body.AppendLine();

            if (winnerPrize > 0)
            {
                body.AppendLine($"<p>{winners.TeamName} will receive ${winnerPrize}</p>");
            }
            if (loserPrize > 0)
            {
                body.AppendLine($"<p>{loser.TeamName} will receive ${loserPrize}</p>");
            }
            body.AppendLine();
            body.AppendLine("<p>Thanks for a great tournament!</p>");
            body.AppendLine("Tournament Tracker");

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

            foreach (TeamModel team in tournament.EnteredTeams)
            {
                foreach (PersonModel person in team.TeamMembers)
                {
                    if (person.EmailAddress.Length > 0)
                    {
                        bcc.Add(person.EmailAddress);
                    }
                }
            }

            EmailLogic.SendEmail(new List <string>(), bcc, subject, body.ToString());
            tournament.CompleteTournament();
        }
        private static void CompleteTournament(TournamentModel model)
        {
            GlobalConfig.Connection.CompleteTournament(model);
            TeamModel winners  = model.Rounds.Last().First().Winner; //Заменяет LOOP THROUGH!!!! Linking
            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 = "";
            //string body = "";
            StringBuilder body = new StringBuilder(); //Соединение строк.

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

            body.AppendLine("<h1>You have a WINNER!</h1>");
            body.AppendLine("<p>Congratulations to our winner!</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) //Check if its valid address
                    {
                        bcc.Add(p.EmailAddress);
                    }
                }
            }

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

            model.CompleteTournament();//Now that event will be fired if tournament is complete!!!!!
        }