Exemplo n.º 1
0
        public void UpdateUser(ADUser user)
        {
            UserPrincipalEx currentADUser = new UserPrincipalEx(Context);
            currentADUser.SamAccountName = user.UserName;

            PrincipalSearcher searcher = new PrincipalSearcher(currentADUser);
            UserPrincipalEx adUser = (UserPrincipalEx)searcher.FindOne();

            if(adUser != null)
            {
                adUser.GivenName = user.FirstName;
                adUser.Surname = user.LastName;
                adUser.Title = user.Title;
                adUser.DisplayName = user.DisplayName;
                adUser.Department = user.Department;
                adUser.Company = user.Company;
                adUser.Info = user.Info;

                adUser.Save();
            }
        }
Exemplo n.º 2
0
        public ADUser GetUserByUserName(string userName)
        {
            ADUser user = new ADUser();
            UserPrincipalEx adUser = new UserPrincipalEx(Context);
            adUser.SamAccountName = userName;

            PrincipalSearcher searcher = new PrincipalSearcher();
            searcher.QueryFilter = adUser;
            UserPrincipalEx searchResult = (UserPrincipalEx)searcher.FindOne();

            if(searchResult != null)
            {
                user.UserName = searchResult.SamAccountName;
                user.FirstName = searchResult.GivenName;
                user.LastName = searchResult.Surname;
                user.PhoneNumber = searchResult.PhoneNumber;
                user.Department = searchResult.Department.Trim();
                user.Title = searchResult.Title;
                user.Email = searchResult.EmailAddress;
                user.Company = searchResult.Company.Trim();
                user.DisplayName = searchResult.DisplayName;
                user.GUID = searchResult.Guid.ToString();
                user.Info = searchResult.Info;
                user.LogonCount = searchResult.LogonCount;
            }

            return user;
        }