示例#1
0
        public Winner PickWinner()
        {
            int randNumber;

            randNumber = rand.Next(numOfContestants);
            contestants[randNumber].IsWinner = true;
            Winner winner = Converter.ConvertContestantToWinner(contestants[randNumber]);

            return(winner);
        }
        public void PickWinner()
        {
            List <int> listOfKeys = new List <int>(contestants.Keys);
            Random     rand       = new Random();
            int        randomKey  = listOfKeys[rand.Next(listOfKeys.Count)];

            contestants[randomKey] = new Winner(contestants[randomKey]);
            UserInterface.PrintWinner(contestants[randomKey], Name);
            NotifyContestents();
        }
示例#3
0
        public ISubscriber PickWinner()
        {
            Random      rand   = new Random();
            int         random = rand.Next(contestants.Count);
            ISubscriber winner = contestants[random];
            Winner      victor = new Winner(winner.firstName, winner.lastName, winner.email, winner.registrationNumber);

            contestants[random] = victor;
            return(winner);
        }
示例#4
0
        public static Winner ConvertContestantToWinner(Contestant contestant)
        {
            Winner winner = new Winner();

            winner.FirstName       = contestant.FirstName;
            winner.LastName        = contestant.LastName;
            winner.Email           = contestant.Email;
            winner.RegistrationNum = contestant.RegistrationNum;

            return(winner);
        }
示例#5
0
 public void NotifyContestants(Winner winner)
 {
     foreach (KeyValuePair <int, Contestant> pair in contestants)
     {
         if (pair.Value.IsWinner == true)
         {
             winner.Notify();
         }
         else
         {
         }
     }
 }
示例#6
0
        // Change the contestant to a winner object and replace it in the Dictionary of contestants.
        private Winner MakeWinnerContestant(Contestant contestant)
        {
            Winner winner = new Winner();

            winner.firstName          = contestant.firstName;
            winner.lastName           = contestant.lastName;
            winner.emailAddress       = contestant.emailAddress;
            winner.registrationNumber = contestant.registrationNumber;

            contestants.Remove(contestant.registrationNumber);      // Remove the contestant
            contestants.Add(winner.registrationNumber, winner);     // Replace with a winner.

            return(winner);
        }
示例#7
0
        public string PickWinner()
        {
            int        index;
            Winner     winner = new Winner();
            int        winnerKey;
            Contestant winnerContestant;
            Random     random = new Random();

            index            = random.Next(0, contestants.Count - 1);
            winnerContestant = contestants.ElementAt(index).Value;
            winnerKey        = contestants.ElementAt(index).Key;
            TransferContestantToWinner(winner, winnerContestant, winnerKey);
            winner.Notify();
            NotifyContestants();
            SendEmail(WinnersMessage(winner));
            return(winner.FirstName + " " + winner.LastName);
        }
示例#8
0
        public void GenerateParticipants()
        {
            IParticipant participant;

            for (int i = 1; i <= registeredContestants.Count; i++)
            {
                if (registeredContestants[i] == winningContestant)
                {
                    string name = registeredContestants[i].FirstName + " " + registeredContestants[i].LastName;
                    participant = new Winner(name);
                    winner      = participant;
                }
                else
                {
                    participant = new Participant(registeredContestants[i].FirstName);
                }
                Subscribe(participant);
            }
        }
示例#9
0
        private MimeMessage WinnersMessage(Winner winner)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("Sweepstakes Manager", "*****@*****.**"));
            message.To.Add(new MailboxAddress(winner.FirstName + winner.LastName, winner.Email));
            message.Subject = "Congratulations! You won the sweepstakes";

            message.Body = new TextPart("plain")
            {
                Text = @"Dear contestant,
                    You have won the sweepstakes, congratulations! Please contact the sweepstakes manager to claim your prize.
                    Sweepstakes manager can be reached at (414) 999-6666. Please have your name, email and registration number when you call

                    --Sweepstakes team"
            };

            return(message);
        }