Ejemplo n.º 1
0
 public SecretSantaService(VonageClient client, SecretSantaContext context, IConfiguration config)
 {
     _client = client;
     _db     = context;
     _config = config;
 }
Ejemplo n.º 2
0
        public void PointSecretSantas()
        {
            var users     = new List <User>();
            var usedUsers = new List <int>();
            var rand      = new Random();

            using (var c = new SecretSantaContext(new DbContextOptions <SecretSantaContext>()))
            {
                Console.WriteLine("Starting the Secret Santa Selection");
                users = c.Users.ToList();

                var couple1 = users.Where(u => (u.UserId == 50 || u.UserId == 53)).ToList();
                Console.WriteLine(couple1.Count);
                var couple2 = users.Where(u => (u.UserId == 57 || u.UserId == 60)).ToList();
                Console.WriteLine(couple2.Count);
                var couple3 = users.Where(u => (u.UserId == 51 || u.UserId == 52)).ToList();
                Console.WriteLine(couple3.Count);

                // Couple 1
                while (new[] { -1, 0, 50, 53 }.Any(x => x == couple1[0].RecipientId) ||
                       usedUsers.Any(x => x == couple1[0].RecipientId))
                {
                    if (couple1[0].RecipientId == 0)
                    {
                        couple1[0].RecipientId = rand.Next(50, 61);
                    }
                }
                usedUsers.Add(couple1[0].RecipientId);
                while (new List <int>()
                {
                    -1, 0, 50, 53
                }.Any(x => x == couple1[1].RecipientId) ||
                       usedUsers.Any(x => x == couple1[1].RecipientId))
                {
                    if (couple1[1].RecipientId == 0)
                    {
                        couple1[1].RecipientId = rand.Next(50, 61);
                    }
                }
                usedUsers.Add(couple1[1].RecipientId);


                // Couple 2
                while (new[] { -1, 0, 57, 60 }.Any(x => x == couple2[0].RecipientId) ||
                       usedUsers.Any(x => x == couple2[0].RecipientId))
                {
                    if (couple2[0].RecipientId == 0)
                    {
                        couple2[0].RecipientId = rand.Next(50, 61);
                    }
                }
                usedUsers.Add(couple2[0].RecipientId);

                while (new[] { -1, 0, 57, 60 }.Any(x => x == couple2[1].RecipientId) ||
                       usedUsers.Any(x => x == couple2[1].RecipientId))
                {
                    if (couple2[1].RecipientId == 0)
                    {
                        couple2[1].RecipientId = rand.Next(50, 61);
                    }
                }
                usedUsers.Add(couple2[1].RecipientId);


                // Couple 3
                while (new[] { -1, 0, 51, 52 }.Any(x => x == couple3[0].RecipientId) &&
                       usedUsers.Any(x => x == couple3[0].RecipientId))
                {
                    if (couple3[0].RecipientId == 0)
                    {
                        couple3[0].RecipientId = rand.Next(50, 61);
                    }
                }
                usedUsers.Add(couple3[0].RecipientId);

                while (new[] { -1, 0, 51, 52 }.Any(x => x == couple3[1].RecipientId) &&
                       usedUsers.Any(x => x == couple3[1].RecipientId))
                {
                    if (couple3[1].RecipientId == 0)
                    {
                        couple3[1].RecipientId = rand.Next(50, 61);
                    }
                }
                usedUsers.Add(couple3[1].RecipientId);


                var singleUsersLeft = c.Users.Where(u => u.RecipientId == 0);
                Console.WriteLine("Single users left");
                foreach (var user in singleUsersLeft)
                {
                    while (new[] { -1, 0 }.Any(x => x == user.RecipientId) &&
                           usedUsers.Any(x => x == user.RecipientId))
                    {
                        if (user.RecipientId == 0)
                        {
                            user.RecipientId = rand.Next(50, 61);
                        }
                    }
                }

                // 50 != 53
                // 57 != 60
                // 51 != 52
                Console.WriteLine(users.Count);
                Console.WriteLine(users[0].Email);

                Console.WriteLine("End Results");
                foreach (var user in users)
                {
                    Console.WriteLine(user.UserId + " " + user.RecipientId + " " + user.Email);
                }

                c.SaveChanges();
            }
        }
Ejemplo n.º 3
0
 protected void Application_Start()
 {
     GlobalConfiguration.Configure(WebApiConfig.Register);
     SecretSantaContext.Create();
 }