private List <UserListBox> GetAllCompanyUsers() { //Get all Membership Users users = Membership.GetAllUsers(); IEnumerable <MembershipUser> allUsers = users.Cast <MembershipUser>(); //Get all Profiles List <UserProfile> allUserProfiles = new List <UserProfile>(); foreach (MembershipUser u in users) { UserProfile registeredUserProfile = UserProfile.GetUserProfile(u.UserName); allUserProfiles.Add(registeredUserProfile); } //Get the CompanyID of the currently logged user UserProfile currentUserProfile = UserProfile.GetUserProfile(); int? companyID = currentUserProfile.CompagnieID; //Join users and their profiles through query where CompanyID equals current logged user CompanyID var userListQuery = (from u in allUsers join p in allUserProfiles on u.UserName equals p.UserName where p.CompagnieID == companyID orderby p.Prenom, p.Nom ascending select new UserListBox { Text = p.Prenom + " " + p.Nom + " (" + p.UserName + ")", Value = p.UserName }).ToList(); return(userListQuery); }
/// <summary> /// The delete all unapproved. /// </summary> /// <param name="createdCutoff"> /// The created cutoff. /// </param> public static void DeleteAllUnapproved(DateTime createdCutoff) { int exitCount = 1; int pageCount = 0; // get all users... // vzrus: we should do it by portions for large forums while (exitCount > 0) { MembershipUserCollection allUsers = GetAllUsers(pageCount, out exitCount, 1000); // iterate through each one... foreach (MembershipUser user in allUsers.Cast <MembershipUser>().Where(user => !user.IsApproved && user.CreationDate < createdCutoff)) { // delete this user... LegacyDb.user_delete(GetUserIDFromProviderUserKey(user.ProviderUserKey)); YafContext.Current.Get <MembershipProvider>().DeleteUser(user.UserName, true); YafContext.Current.Get <ILogger>() .Log( YafContext.Current.PageUserID, "UserMembershipHelper.DeleteAllUnapproved", "User {0} was deleted by user id {1} as unapproved.".FormatWith( user.UserName, YafContext.Current.PageUserID), EventLogTypes.UserDeleted); } pageCount++; } }
/// <summary> /// For the admin function: approve all users. Approves all /// users waiting for approval /// </summary> public static void ApproveAll() { int exitCount = 1; int pageCount = 0; // get all users... // vzrus: we should do it by portions for large forums while (exitCount > 0) { MembershipUserCollection allUsers = GetAllUsers(pageCount, out exitCount, 1000); // iterate through each one... foreach (MembershipUser user in allUsers.Cast <MembershipUser>().Where(user => !user.IsApproved)) { // approve this user... user.IsApproved = true; YafContext.Current.Get <MembershipProvider>().UpdateUser(user); int id = GetUserIDFromProviderUserKey(user.ProviderUserKey); if (id > 0) { LegacyDb.user_approve(id); } } pageCount++; } }
public static IEnumerable <MembershipUser> Search(this MembershipUserCollection m, string searchText) { var users = m.Cast <MembershipUser>().ToList(); var profiles = users.Select(u => UserProfile.GetUserProfile(u.UserName)).ToList(); var foundUserNames = profiles.Search(searchText).Select(p => p.UserName); return(users.Where(u => foundUserNames.Contains(u.UserName)).ToList()); }
public ActionResult Index(int pageIndex = 0, int pageSize = 30) { int numberOfUsers; MembershipUserCollection users = Membership.GetAllUsers(pageIndex, pageSize, out numberOfUsers); IndexViewModel model = new IndexViewModel(); model.Users = users.Cast <MembershipUser>() .AsEnumerable() .MapTo <User>() .ToPagedResult(pageIndex, pageSize, numberOfUsers); model.Users.Result.ForEach(u => u.Roles = Roles.GetRolesForUser(u.Username).ToList()); return(this.View(model)); }
private static IEnumerable <MembershipUserDto> Map(MembershipUserCollection users) { return(users.Cast <MembershipUser>().Select(Map).ToList()); }
public static List <String> GetAllUsers() { MembershipUserCollection users = Membership.GetAllUsers(); return(users.Cast <MembershipUser>().Select(mu => mu.UserName).ToList()); }