Beispiel #1
0
        public void Notify(ISubscriber subscriber, Sweepstakes sweepstakes, Contestant winner)
        {
            StringBuilder name = new StringBuilder();

            name.Append(FirstName);
            name.Append(" ");
            name.Append(LastName);
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(sweepstakes.Name, APIKeys.Email));
            message.To.Add(new MailboxAddress(name.ToString(), subscriber.EmailAddress));
            if (subscriber == winner)
            {
                message.Subject = "Congratulations!";
                message.Body    = new TextPart("plain")
                {
                    Text = @"Congratulations,

You've won the sweepstakes! Take some money!"
                };
            }
            else
            {
                message.Subject = "Sweepstakes Winner Announced!";
                message.Body    = new TextPart("plain")
                {
                    Text = @"Hello,

The winner of the sweepstakes is " + winner.FirstName + " " + winner.LastName + "."
                };
            }

            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587, false);
                client.Authenticate(APIKeys.Email, APIKeys.Password);
                client.Send(message);
                client.Disconnect(true);
            }
        }
Beispiel #2
0
        public void Notify(ISubscriber subscriber, Sweepstakes sweepstakes, Contestant winner)
        {
            StringBuilder name    = new StringBuilder();
            var           message = new MimeMessage();

            message.From.Add(new MailboxAddress(sweepstakes.Name, APIKeys.Email));
            message.To.Add(new MailboxAddress("Marketing Firm", subscriber.EmailAddress));
            message.Subject = "Sweepstakes Winner Announced!";
            message.Body    = new TextPart("plain")
            {
                Text = @"Hello,

The winner of the sweepstakes is " + winner.FirstName + " " + winner.LastName + "."
            };

            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587, false);
                client.Authenticate(APIKeys.Email, APIKeys.Password);
                client.Send(message);
                client.Disconnect(true);
            }
        }
Beispiel #3
0
        public void Run()
        {
            CreateMarketingFirmWithManager();
            string email = UserInterface.GetUserInputFor("email");

            marketingFirm.EmailAddress = email;
            bool addSweepstakes = UserInterface.WillContinue("add sweepstakes");

            while (addSweepstakes)
            {
                marketingFirm.CreateSweepstake();
                addSweepstakes = UserInterface.WillContinue("add sweepstakes");
            }
            Sweepstakes sweepstake = manager.GetSweepstakes();
            bool        pickWinner = true;

            while (pickWinner && sweepstake != null)
            {
                pickWinner = UserInterface.WillContinue("pick winner");
                Contestant winner = sweepstake.PickWinner();
                sweepstake.NotifyUsersOfWinner(marketingFirm, winner);
                sweepstake = manager.GetSweepstakes();
            }
        }
 public static void AssignRegistrationNumber(Contestant contestant, int totalAdded)
 {
     contestant.RegistrationNumber = totalAdded + 1;
 }