Пример #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Surname,Address,Email,PhoneNumber")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
Пример #2
0
        private static void PopulateDirectory()
        {
            using (var context = new DirectoryContext())
            {
                int entryCount = context.Query <LdsUser>().Count();
                if (entryCount > 1)
                {
                    Console.WriteLine("Directory already populated with {0} entries", entryCount);
                    return;
                }
            }

            var employees = new LdsUser[50000];

            Parallel.For(0, 50000, i =>
            {
                var firstName         = GetRandomName() + i;
                var lastName          = GetRandomName() + i;
                var distinguishedName = "CN=" + firstName + " " + lastName + "," + UserDirectoryContainer;
                var employee          = new LdsUser
                {
                    DistinguishedName = distinguishedName,
                    Employees         = new Collection <LdsUser>(),
                    FirstName         = firstName,
                    LastName          = lastName,
                    EmployeeId        = 50 + i,
                    Comment           = "This entry was generated by random data.",
                    PhoneNumber       = "(123) 555-9857",
                    Title             = GetRandomTitle(),
                    Street            = "1234 Cool St.",
                    City       = GetRandomCity(),
                    Country    = GetRandomCountry(),
                    PostalCode = "12345"
                };

                employees[i] = employee;
            });

            var random = new Random(10000);

            int count = 0;

            foreach (var employee in employees)
            {
                if (count % 7 == 0)
                {
                    var index = random.Next(0, 50000);
                    var e     = employees[index];
                    if (e != employee && e.Manager == null)
                    {
                        e.Manager = employee.DistinguishedName;
                        employee.Employees.Add(e);
                    }
                }
                count++;
            }

            var managers = employees.Where(e => e.Manager == null).ToList();

            foreach (var employee in managers.AsParallel())
            {
                using (var context = new DirectoryContext())
                {
                    context.Add(employee);

                    if (employee.Employees != null && employee.Employees.Count > 0)
                    {
                        foreach (var subordinate in employee.Employees)
                        {
                            if (subordinate.Manager != employee.DistinguishedName)
                            {
                                throw new Exception("What?");
                            }
                            context.Add(subordinate);
                        }
                    }
                }
                Console.WriteLine("{0} added", employee.DistinguishedName);

                if (employee.Employees == null)
                {
                    continue;
                }

                foreach (var e in employee.Employees)
                {
                    Console.WriteLine("{0} added", e.DistinguishedName);
                }
            }
        }
Пример #3
0
        private static void PropulateDirectoryForInheritance()
        {
            AddContainerIfNecessary("CN", "InheritanceTest");

            using (var context = new DirectoryContext())
            {
                int entryCount = context.Query(InheritanceDirectoryContainer).Count();
                if (entryCount > 1)
                {
                    Console.WriteLine("Inheritince Directory already populated with {0} entries", entryCount);
                    return;
                }
            }

            var users = new DirectoryAttributes[10000];

            Parallel.For(0, 10000, i =>
            {
                var firstName         = GetRandomName() + i;
                var lastName          = GetRandomName() + i;
                var distinguishedName = "CN=" + firstName + " " + lastName + "," + InheritanceDirectoryContainer;

                var user = new DirectoryAttributes(distinguishedName);

                var objectClass = i % 5 == 0 ? "user" : (i % 3 == 0 ? "organizationalPerson" : "person");

                user.Set("objectClass", objectClass);

                if (objectClass == "user")
                {
                    user.Set("givenname", firstName)
                    .Set("sn", lastName)
                    .Set("employeeid", 50 + i)
                    .Set("comment", "This entry was generated by random data.")
                    .Set("telephonenumber", "(123) 555-9857")
                    .Set("title", GetRandomTitle())
                    .Set("street", "1234 Cool St.")
                    .Set("l", GetRandomCity())
                    .Set("c", GetRandomCountry())
                    .Set("PostalCode", "12345");
                }
                else if (objectClass == "person")
                {
                    user.Set("sn", lastName);
                }
                else
                {
                    user.Set("givenname", firstName)
                    .Set("sn", lastName)
                    .Set("employeeid", 50 + i)
                    .Set("comment", "This entry was generated by random data.")
                    .Set("telephonenumber", "(123) 555-9857")
                    .Set("title", GetRandomTitle())
                    .Set("street", "1234 Cool St.")
                    .Set("l", GetRandomCity())
                    .Set("c", GetRandomCountry())
                    .Set("postalCode", "12345");
                }


                users[i] = user;
            });

            foreach (var user in users.AsParallel())
            {
                using (var context = new DirectoryContext())
                {
                    context.Add(user);
                }
                Console.WriteLine("{0} added", user.DistinguishedName);
            }
        }