Example #1
0
        public void RandomNameSelector()
        {
            List <Participant> participants = new SecretSanta().SecretSantaList(data.ParticipantCsvData);

            var secretSantaList = new Dictionary <string, string>();

resrtart:
            foreach (var participant in participants)
            {
                var azar         = new Random();
                var giftReciever = participants.ElementAt(azar.Next(0, participants.Count));
                int iterations   = 0;
                while (secretSantaList.ContainsKey(giftReciever.Name) || true && participant.Name == giftReciever.Name || giftReciever.Name == participant.Partner)
                {
                    giftReciever = participants.ElementAt(azar.Next(0, participants.Count));
                    iterations++;
                    if (iterations > 9)
                    {
                        break;
                    }
                }
                try
                {
                    secretSantaList.Add(giftReciever.Name, participant.Name);
                    new SecretSanta().SendEmail(participant, giftReciever.Name);
                }
                catch (Exception)
                {
                    secretSantaList.Clear();
                    goto resrtart;
                }
            }
        }
Example #2
0
        static void Main()
        {
            var secretSanta = new SecretSanta();

            secretSanta.RandomNameSelector();
        }