예제 #1
0
        public List <User> GetMatchingUsersFromDatabase(string searchString)
        {
            BootcampRepository repo = new BootcampRepository();
            var users = repo.Query <User>().Where(u => u.Fullname.ToLower().Contains(searchString.ToLower())).ToList();

            return(users);
        }
예제 #2
0
        public void DispatcherTimerTick(object sender)
        {
            BootcampRepository repo = new BootcampRepository();

            using (var pc = new PrincipalContext(ContextType.Domain, _loginProvider.GetConnectionString()))
            {
                UserPrincipal qbeUser = new UserPrincipal(pc);
                qbeUser.DisplayName = "*";
                PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
                foreach (var found in srch.FindAll())
                {
                    UserPrincipal user = (found as UserPrincipal);
                    if (user != null)
                    {
                        //Infusion hack: remove users that start with ext- or that have - or _ in their username
                        if (/*user.SamAccountName.Contains("-") ||*/ user.SamAccountName.Contains("_"))
                        {
                            continue;
                        }
                        User dbUser = repo.Query <User>().FirstOrDefault(u => u.Username == user.SamAccountName);
                        if (dbUser == null)
                        {
                            dbUser = new DomanUserLoginProvider(_loginProvider.GetConnectionString()).CreateUser(user.SamAccountName);
                            if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username))
                            {
                                repo.Add <User>(dbUser);
                            }
                        }
                    }
                }
            }
            repo.SaveChanges();
        }
예제 #3
0
        public List <User> GetMatchingUsersFromDomain(string searchString)
        {
            try
            {
                List <User>        userList = new List <User>();
                BootcampRepository repo     = new BootcampRepository();
                using (var pc = new PrincipalContext(ContextType.Domain, _domain))
                {
                    UserPrincipal qbeUser = new UserPrincipal(pc);
                    qbeUser.DisplayName = string.Format("*{0}*", searchString);
                    PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
                    foreach (var found in srch.FindAll())
                    {
                        UserPrincipal user = (found as UserPrincipal);
                        if (user != null)
                        {
                            //Infusion hack: remove users that start with ext- or that have - or _ in their username
                            if (user.SamAccountName.Contains("-") || user.SamAccountName.Contains("_"))
                            {
                                continue;
                            }
                            User dbUser = repo.Query <User>().FirstOrDefault(u => u.Username == user.SamAccountName);
                            if (dbUser == null)
                            {
                                dbUser = new DomanUserLoginProvider(_domain).CreateUser(user.SamAccountName);
                                if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username))
                                {
                                    repo.Add <User>(dbUser);
                                }
                            }
                            if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username))
                            {
                                userList.Add(dbUser);
                            }
                        }
                    }
                }

                repo.SaveChanges();
                return(userList);
            }
            catch (Exception ex)
            {
                Log.Error("Cannot connect to domain", ex);
                return(null);
            }
        }