src/Folke.Identity.Elm/UserStore.cs
/// <summary>
///     Returns true if the user is in the named role
/// </summary>
/// <param name="user"></param>
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Returns true if the user is in the named role
Returns true if the user is in the named role
public virtual async Task<bool> IsInRoleAsync(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));
            }
            var role = await connection.SelectAllFrom<IdentityRole<TKey>>().Where(r => r.Name == roleName).SingleOrDefaultAsync();
            if (role != null)
            {
                return (await connection.SelectAllFrom<IdentityUserRole<TUser, TKey>>().Where(ur => ur.Role == role && ur.User == user).SingleOrDefaultAsync()) != null;
            }
            return false;
        }
public virtual async Task < bool > IsInRoleAsync ( 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 ) ) ; } var role = await connection . SelectAllFrom < IdentityRole < TKey > > ( ) . Where ( r => r . Name == roleName ) . SingleOrDefaultAsync ( ) ; if ( role != null ) { return ( await connection . SelectAllFrom < IdentityUserRole < TUser , TKey > > ( ) . Where ( ur => ur . Role == role && ur . User == user ) . SingleOrDefaultAsync ( ) ) != null ; } return false ; }
Returns true if the user is in the named role
Returns true if the user is in the named role
None
user
TUser
None
roleName
string
None
cancellationToken
CancellationToken
None