src/Folke.Identity.Elm/UserStore.cs
/// <summary>
///     Add a user to a role
/// </summary>
/// <param name="user"></param>
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Add a user to a role
Add a user to a role
public virtual async Task AddToRoleAsync(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("roleName");
            }
            roleName = roleName.ToLowerInvariant();
            var roleEntity = await connection.SelectAllFrom<IdentityRole<TKey>>().Where(r => r.NormalizedName == roleName).SingleOrDefaultAsync();
            if (roleEntity == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Role {0} not found", roleName));
            }
            var ur = new IdentityUserRole<TUser, TKey> { User = user, Role = roleEntity };
            await connection.SaveAsync(ur);
        }
public virtual async Task AddToRoleAsync ( 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 ( " " ) ; } roleName = roleName . ToLowerInvariant ( ) ; var roleEntity = await connection . SelectAllFrom < IdentityRole < TKey > > ( ) . Where ( r => r . NormalizedName == roleName ) . SingleOrDefaultAsync ( ) ; if ( roleEntity == null ) { throw new InvalidOperationException ( String . Format ( CultureInfo . CurrentCulture , " " , roleName ) ) ; } var ur = new IdentityUserRole < TUser , TKey > { User = user , Role = roleEntity } ; await connection . SaveAsync ( ur ) ; }
Add a user to a role
Add a user to a role
None
user
TUser
None
roleName
string
None
cancellationToken
CancellationToken
None