src/Folke.Identity.Elm/UserStore.cs
/// <summary>
///     Remove a user from a role
/// </summary>
/// <param name="user"></param>
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Remove a user from a role
Remove a user from a role
public virtual async Task RemoveFromRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (String.IsNullOrWhiteSpace(roleName))
            {
                throw new ArgumentException(nameof(roleName));
            }
            roleName = roleName.ToLowerInvariant();
            var roleEntity = await connection.SelectAllFrom<IdentityRole<TKey>>().Where(r => r.NormalizedName == roleName).SingleOrDefaultAsync();
            if (roleEntity != null)
            {
                var userRole = await connection.SelectAllFrom<IdentityUserRole<TUser, TKey>>().Where(r => roleEntity == r.Role && r.User == user).SingleOrDefaultAsync();
                if (userRole != null)
                {
                    await connection.DeleteAsync(userRole);
                }
            }
        }
public virtual async Task RemoveFromRoleAsync ( TUser user , string roleName , CancellationToken cancellationToken = default ( CancellationToken ) ) { cancellationToken . ThrowIfCancellationRequested ( ) ; ThrowIfDisposed ( ) ; if ( user == null ) { throw new ArgumentNullException ( nameof ( user ) ) ; } if ( String . IsNullOrWhiteSpace ( roleName ) ) { throw new ArgumentException ( nameof ( roleName ) ) ; } roleName = roleName . ToLowerInvariant ( ) ; var roleEntity = await connection . SelectAllFrom < IdentityRole < TKey > > ( ) . Where ( r => r . NormalizedName == roleName ) . SingleOrDefaultAsync ( ) ; if ( roleEntity != null ) { var userRole = await connection . SelectAllFrom < IdentityUserRole < TUser , TKey > > ( ) . Where ( r => roleEntity == r . Role && r . User == user ) . SingleOrDefaultAsync ( ) ; if ( userRole != null ) { await connection . DeleteAsync ( userRole ) ; } } }
Remove a user from a role
Remove a user from a role
None
user
TUser
None
roleName
string
None
cancellationToken
CancellationToken
None