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 }); }
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)); }
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)); }
public Task <ApplicationRole> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); normalizedRoleName.ThrowIfNull(nameof(normalizedRoleName)); return(_rolesTable.FindByNameAsync(normalizedRoleName)); }