Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Surname,Address,Email,PhoneNumber")] Person person)
        {
            if (id != person.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
Example #2
0
        private static void PopulateDirectoryForTests()

        {
            var user2Container = DnParser.ParseName(TestUserDirectoryContainer);

            var user2Prefix = DnParser.ParseRDN(TestUserDirectoryContainer);

            AddContainerIfNecessary(user2Prefix, user2Container);

            using (var context = new DirectoryContext())

            {
                AddEntryIfNecessary("CN=PasswordUser," + TestUserDirectoryContainer, "user", context);

                AddEntryIfNecessary("CN=persontest," + TestUserDirectoryContainer, "user", context);

                AddEntryIfNecessary("CN=TestUser," + TestUserDirectoryContainer, "user", context);

                AddEntryIfNecessary("CN=TestUser2," + TestUserDirectoryContainer, "user", context);
            }

            var roleContainer = DnParser.ParseName(RolesDirectoryContainer);

            var rolePrefix = DnParser.ParseRDN(RolesDirectoryContainer);

            AddContainerIfNecessary(rolePrefix, roleContainer);

            using (var context = new DirectoryContext())

            {
                IDirectoryAttributes rangeTest = AddEntryIfNecessary("CN=RangeTest," + RolesDirectoryContainer, "group", context);

                foreach (var kvp in rangeTest.Where(kvp => kvp.Key.StartsWith("member", StringComparison.OrdinalIgnoreCase)))

                {
                    if (kvp.Value is IEnumerable <string> && ((IEnumerable <string>)kvp.Value).Any())

                    {
                        Console.WriteLine("RangeTest members already populated");

                        return;
                    }
                }

                var newMembers = new List <string>();

                newMembers.AddRange(context.Query <LdsUser>().Take(10000).Select(u => u.DistinguishedName));

                rangeTest.Set("member", newMembers);

                context.Update(rangeTest);
            }
        }
Example #3
0
        private static void EnablePasswordChangesOn389()

        {
            using (var context = new DirectoryContext())

            {
                var attributes = context.ListServerAttributes("namingcontexts");

                var namingContexts = attributes.GetStrings("namingcontexts");

                var configurationDN = namingContexts != null

                                          ? namingContexts

                                      .FirstOrDefault(s => DnParser.ParseName(s)

                                                      .Equals("Configuration", StringComparison.OrdinalIgnoreCase))

                                          : null;

                bool success = false;

                if (configurationDN != null)

                {
                    var directoryService = context.Query(configurationDN)

                                           .Where(_ => Filter.Equal(_, "cn", "Directory Service", true))

                                           .Select("distinguishedName")

                                           .FirstOrDefault();

                    if (directoryService != null)

                    {
                        directoryService.Set("dSHeuristics", "0000000001001");

                        context.Update(directoryService);

                        success = true;
                    }
                }

                if (!success)

                {
                    Console.WriteLine("Could not set a password policy");
                }
            }
        }
Example #4
0
 public async Task <bool> UpdateUser(UserModel userModel)
 {
     if (userModel == null)
     {
         throw new ArgumentNullException();//to change to custom exception
     }
     try
     {
         var user = _context.Users.Where(w => w.UserName == userModel.UserName).FirstOrDefault();
         if (user == null)
         {
             return(false);
         }
         user.Id                  = userModel.Id;
         user.Address1            = userModel.Address1;
         user.Age                 = userModel.Age;
         user.Birthday            = userModel.Birthday;
         user.CivilStatus         = userModel.CivilStatus;
         user.ContactNumber       = userModel.ContactNumber;
         user.Country             = userModel.Country;
         user.Department          = userModel.Department;
         user.FirstName           = userModel.FirstName;
         user.Gender              = userModel.Gender;
         user.HireDate            = userModel.HireDate;
         user.HobbiesAndInterest  = userModel.HobbiesAndInterest;
         user.LanguagesSpoken     = userModel.LanguagesSpoken;
         user.LastName            = userModel.LastName;
         user.Password            = userModel.Password;
         user.PasswordAttemptFail = userModel.PasswordAttemptFail;
         user.State               = userModel.State;
         user.UserType            = userModel.UserType.ToString();
         user.UserName            = userModel.UserName;
         _context.Update(user);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }