public override IList<RainbowRole> GetRolesForUser( string portalAlias, Guid userId ) {
            IList<RainbowRole> result = new List<RainbowRole>();

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "aspnet_UsersInRoles_GetRolesForUser";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Connection = new SqlConnection( connectionString );

            cmd.Parameters.Add( "@ApplicationName", SqlDbType.NVarChar, 256 ).Value = portalAlias;
            cmd.Parameters.Add( "@UserId", SqlDbType.UniqueIdentifier ).Value = userId;

            SqlParameter returnCode = cmd.Parameters.Add( "@ReturnCode", SqlDbType.Int );
            returnCode.Direction = ParameterDirection.ReturnValue;

            SqlDataReader reader = null;
            try {
                cmd.Connection.Open();

                using ( reader = cmd.ExecuteReader() ) {

                    while ( reader.Read() ) {

                        RainbowRole role = GetRoleFromReader( reader );

                        result.Add( role );
                    }
                    reader.Close();
                    if ( ( ( int )returnCode.Value ) == 1 ) {
                        throw new RainbowRoleProviderException( "User doesn't exist" );
                    }
                }

                return result;
            }
            catch ( SqlException e ) {
                if ( WriteExceptionsToEventLog ) {
                    WriteToEventLog( e, "GetAllRoles" );
                }

                throw new RainbowRoleProviderException( "Error executing aspnet_Roles_GetAllRoles stored proc", e );
            }
            catch ( RainbowRoleProviderException ) {
                throw;
            }
            catch ( Exception e ) {
                if ( WriteExceptionsToEventLog ) {
                    WriteToEventLog( e, "GetAllRoles" );
                }

                throw new RainbowRoleProviderException( "Error getting roles for user " + userId.ToString(), e );
            }
            finally {
                if ( reader != null ) {
                    reader.Close();
                }
                cmd.Connection.Close();
            }
        }
 public int CompareTo(object obj)
 {
     if (obj is RainbowRole)
     {
         RainbowRole role = ( RainbowRole )obj;
         return(name.CompareTo(role.name));
     }
     throw new ArgumentException("object is not a RainbowRole");
 }
        public override bool Equals(object obj)
        {
            //Check for null and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            RainbowRole role = ( RainbowRole )obj;

            return((id == role.id) && (name == role.name));
        }
        public override bool IsUserInRole( string username, string roleName ) {

            RainbowUser user = ( RainbowUser )Membership.GetUser( username );

            if ( user == null ) {
                throw new RainbowRoleProviderException( "User doesn't exist" );
            }

            RainbowRole role = GetRoleByName( ApplicationName, roleName );

            return IsUserInRole( ApplicationName, user.ProviderUserKey, role.Id );
        }
        public override IList<RainbowRole> GetAllRoles( string portalAlias ) {

            IList<RainbowRole> result = new List<RainbowRole>();
            result.Insert( 0, new RainbowRole( AllUsersGuid, AllUsersRoleName, AllUsersRoleName ) );
            result.Insert( 1, new RainbowRole( AuthenticatedUsersGuid, AuthenticatedUsersRoleName, AuthenticatedUsersRoleName ) );
            result.Insert( 2, new RainbowRole( UnauthenticatedUsersGuid, UnauthenticatedUsersRoleName, UnauthenticatedUsersRoleName ) );

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "aspnet_Roles_GetAllRoles";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Connection = new SqlConnection( connectionString );

            cmd.Parameters.Add( "@ApplicationName", SqlDbType.NVarChar, 256 ).Value = portalAlias;

            SqlDataReader reader = null;
            try {
                cmd.Connection.Open();

                using ( reader = cmd.ExecuteReader() ) {

                    while ( reader.Read() ) {
                        RainbowRole role = GetRoleFromReader( reader );

                        result.Add( role );
                    }
                    reader.Close();
                }

                return result;
            }
            catch ( SqlException e ) {
                if ( WriteExceptionsToEventLog ) {
                    WriteToEventLog( e, "GetAllRoles" );
                }

                throw new RainbowRoleProviderException( "Error executing aspnet_Roles_GetAllRoles stored proc", e );
            }
            catch ( Exception e ) {
                if ( WriteExceptionsToEventLog ) {
                    WriteToEventLog( e, "GetAllRoles" );
                }

                throw new RainbowRoleProviderException( "Error getting all roles", e );
            }
            finally {
                if ( reader != null ) {
                    reader.Close();
                }
                cmd.Connection.Close();
            }
        }
        public override void AddUsersToRoles( string[] usernames, string[] roleNames ) {
            Guid[] userIds = new Guid[usernames.Length];
            Guid[] roleIds = new Guid[roleNames.Length];

            RainbowUser user = null;
            for ( int i = 0; i < usernames.Length; i++ ) {
                user = ( RainbowUser )Membership.GetUser( usernames[i] );

                if ( user == null ) {
                    throw new RainbowMembershipProviderException( "User " + usernames[i] + " doesn't exist" );
                }

                userIds[i] = user.ProviderUserKey;
            }

            RainbowRole role = null;
            for ( int i = 0; i < roleNames.Length; i++ ) {
                role = GetRoleByName( ApplicationName, roleNames[i] );
                roleIds[i] = role.Id;
            }

            AddUsersToRoles( ApplicationName, userIds, roleIds );
        }
 public override string[] GetUsersInRole( string roleName ) {
     RainbowRole role = GetRoleByName( ApplicationName, roleName );
     return GetUsersInRole( ApplicationName, role.Id );
 }
        public override bool DeleteRole( string roleName, bool throwOnPopulatedRole ) {
            RainbowRole role = GetRoleByName( ApplicationName, roleName );

            return DeleteRole( ApplicationName, role.Id, throwOnPopulatedRole );
        }