public MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
 {
     MembershipUserCollection users = new ProfilesDBMembershipProviderDA().GetUsersByName(usernameToMatch);
     totalRecords = users.Count;
     return users;
     //return new ProfilesDBMembershipProviderDA().FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords);
 }
    private void RemoveUserFromRole(string username, string rolename)
    {
        if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(rolename))
        {
            DataRow l_UserRow = new ProfilesDBMembershipProviderDA().GetUser(username, false);

            int? l_RoleId = new RoleProviderDA().GetRoleIDByName(rolename);

            RoleProviderDA l_RPDA = new RoleProviderDA();

            if (l_UserRow != null && l_RoleId.HasValue)
            {
                int l_UserId = (int) l_UserRow["UserID"];
                l_RPDA.RemoveUserFromRole(l_UserId, l_RoleId.Value);
            }
        }
    }
    private void AddUserToRole(string p_UserName, string p_UserRole)
    {
        DataRow l_DataRowUser = new ProfilesDBMembershipProviderDA().GetUser(p_UserName, false);
        int? l_RoleID = new RoleProviderDA().GetRoleIDByName(p_UserRole);

        if (l_DataRowUser != null && l_RoleID.HasValue)
        {
            int l_UserID = (int)l_DataRowUser["UserID"];

            if (!UserExistsInRole(l_UserID, l_RoleID.Value))
                AddUserRole(l_UserID, l_RoleID.Value);
        }
    }
    public bool UserExistsInRole(string username, string rolename)
    {
        DataRow l_DataRowUser = new ProfilesDBMembershipProviderDA().GetUser(username, false);
        int? l_RoleID = new RoleProviderDA().GetRoleIDByName(rolename);

        if (l_DataRowUser != null && l_RoleID.HasValue)
        {
            int l_UserID = (int)l_DataRowUser["UserID"];
            return UserExistsInRole(l_UserID, l_RoleID.Value);
        }
        return false;
    }
    public string[] GetRolesForUser(string username)
    {
        DataRow l_UserRow = new ProfilesDBMembershipProviderDA().GetUser(username, false);
        if (l_UserRow != null)
        {
            int l_UserID = (int) l_UserRow["UserID"];
            DataTable l_userRoleTable = GetUserRoles(l_UserID);

            List<string> roleNames = new List<string>();
            foreach (DataRow l_RoleRow in l_userRoleTable.Rows)
            {
                //int l_RoleID = (int)l_RoleRow["RoleName"];
                //string l_RoleName = dbRole.GetRoleName(l_RoleID);
                roleNames.Add(l_RoleRow["RoleName"].ToString());
            }
            return roleNames.ToArray();
        }

        return null;
    }
        //this Method invoke by ObjectDataSource
        public MembershipUserCollection GetAllUsers(string search, int startRowIndex, int maximumRows)
        {
            int totalRecords;
            int pageIndex = 0;
            if (maximumRows != 0) pageIndex = startRowIndex / maximumRows;

            MembershipUserCollection users = new ProfilesDBMembershipProviderDA().GetAllUsers(pageIndex,
                                                                                              maximumRows, search,
                                                                                              out totalRecords);
            return users;
        }
 public MembershipUser GetUserByID(int p_UserID)
 {
     MembershipUser user = null;
     try
     {
         DataRow userRow = new ProfilesDBMembershipProviderDA().GetUserByID(p_UserID);
         user = GetUserFromTableRow(userRow);
     }
     catch (Exception ex)
     {
         bool l_Rethrow = ExceptionPolicy.HandleException(ex, GlobalConst.LogOnlyPolicy);
         if (l_Rethrow) throw;
     }
     return user;
 }
        public ProfilesMembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            IDataReader userReader;
            ProfilesMembershipUser memberUser = null;

            userReader = new ProfilesDBMembershipProviderDA().GetUser(providerUserKey, userIsOnline);

            if (((System.Data.SqlClient.SqlDataReader)userReader).HasRows)
            {
                userReader.Read();
                memberUser = this.GetUserFromReader(userReader);
            }

            return memberUser;
        }
        public ProfilesMembershipUser GetUser(string username, bool updateUserActivity)
        {
            DataRow userRow = null;
            ProfilesMembershipUser memberUser = null;

            userRow = new ProfilesDBMembershipProviderDA().GetUser(username, updateUserActivity);
            memberUser = GetUserFromTableRow(userRow);

            return memberUser;
        }