Esempio n. 1
0
        private List <UserRefreshModel> GetAllUserData()
        {
            List <UserRefreshModel> model = new List <UserRefreshModel>();

            using (var context = new PrincipalContext(ContextType.Domain, "safety.northernsafety.com"))
            {
                using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
                {
                    foreach (var result in searcher.FindAll())
                    {
                        UserRefreshModel singleUser = new UserRefreshModel();

                        DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
                        if (de != null && de.Properties["givenName"].Value != null && de.Properties["physicalDeliveryOfficeName"].Value != null && de.Properties["department"].Value != null)
                        {
                            singleUser.FirstName  = de.Properties["givenName"].Value.ToString();
                            singleUser.LastName   = de.Properties["sn"].Value != null ? de.Properties["sn"].Value.ToString() : "";
                            singleUser.EMail      = de.Properties["mail"].Value != null ? de.Properties["mail"].Value.ToString() : "";
                            singleUser.UserName   = de.Properties["sAMAccountName"].Value != null ? de.Properties["sAMAccountName"].Value.ToString() : "";
                            singleUser.Location   = de.Properties["physicalDeliveryOfficeName"].Value.ToString();
                            singleUser.Department = de.Properties["department"].Value.ToString();
                            var sidBytes           = (byte[])de.Properties["objectSid"].Value;
                            SecurityIdentifier sid = new SecurityIdentifier(sidBytes, 0);
                            singleUser.SID = sid.ToString();

                            model.Add(singleUser);
                        }
                    }
                }
            }

            return(model);
        }
Esempio n. 2
0
 private ServiceDesk_Users MapRefreshModelToEFModel(UserRefreshModel refreshModel)
 {
     return(new ServiceDesk_Users
     {
         SID = refreshModel.SID,
         UserName = refreshModel.UserName,
         FirstName = refreshModel.FirstName,
         LastName = refreshModel.LastName,
         EMail = refreshModel.EMail,
         LocationId = refreshModel.LocationId ?? 0,
         DepartmentId = refreshModel.DepartmentId ?? 0
     });
 }