Exemplo n.º 1
0
        public async Task AddToRoleAsync(ApplicationUser user, string roleName, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            user.ThrowIfNull(nameof(user));
            roleName.ThrowIfNull(nameof(roleName));
            var role = await _rolesTable.FindByNameAsync(roleName);

            if (role == null)
            {
                return;
            }

            user.Roles ??= (await _usersRolesTable.GetRolesAsync(user)).ToList();

            if (await IsInRoleAsync(user, roleName, cancellationToken))
            {
                return;
            }

            user.Roles.Add(new UserRole
            {
                RoleName = roleName,
                RoleId   = role.Id
            });
        }
Exemplo n.º 2
0
        public Task <ApplicationRole> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(normalizedRoleName))
            {
                throw new ArgumentNullException(nameof(normalizedRoleName), "Parameter normalizedRoleName cannot be null or empty.");
            }

            cancellationToken.ThrowIfCancellationRequested();
            return(_rolesTable.FindByNameAsync(normalizedRoleName));
        }
Exemplo n.º 3
0
        public override async Task <IdentityRole <TKey> > FindByNameAsync(string normalizedName, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (string.IsNullOrEmpty(normalizedName))
            {
                throw new ArgumentException($"Parameter {nameof(normalizedName)} cannot be null or empty.");
            }

            return(await RolesTable.FindByNameAsync(normalizedName));
        }
Exemplo n.º 4
0
 public Task <ApplicationRole> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     normalizedRoleName.ThrowIfNull(nameof(normalizedRoleName));
     return(_rolesTable.FindByNameAsync(normalizedRoleName));
 }