Beispiel #1
0
        public void PickAWinner(Random rng)
        {
            if (listOfSweeps.Count < 1)
            {
                return;
            }
            //Which sweepstakes?
            UserInterface.DisplaySweeps(listOfSweeps);
            string userInput = UserInterface.GetUserInputFor("Which sweepstakes would you like to pick a winner for?\n\nType 'cancel' to cancel...");

            while (activeSweep == null && userInput != "cancel")
            {
                for (int i = 0; i < listOfSweeps.Count; i++)
                {
                    if (listOfSweeps[i].Name == userInput)
                    {
                        //activeSweep = listOfSweeps[i];
                        activeSweep = _manager.GetSweepstakes(userInput);
                    }
                }
                if (activeSweep == null)
                {
                    UserInterface.DisplaySweeps(listOfSweeps);
                    userInput = UserInterface.GetUserInputFor("Which sweepstakes would you like to pick a winner for?\n\nType 'cancel' to cancel...");
                }
            }
            if (userInput == "cancel")
            {
                return;
            }
            bool isEmpty = activeSweep.CheckIfContestantsIsEmpty();

            //Randomly generate int to pick contestant from dictionary based on their key
            if (isEmpty == false)
            {
                sweepWinner = activeSweep.PickWinner(rng);
            }
            else
            {
                UserInterface.DisplayContestantsIsEmptyError();
                Console.ReadKey();
                Console.Clear();
                return;
            }
            activeSweep.PrintContestantInfo(sweepWinner);
            //Notify all contestants of their win/loss
            //Integrate the mailAPI
            activeSweep.SendEmailToWinner(sweepWinner);
            activeSweep.SendEmailToLosers();
            activeSweep = null;
        }