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 = 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) { cancellationToken.ThrowIfCancellationRequested(); normalizedRoleName.ThrowIfNull(nameof(normalizedRoleName)); return(_rolesTable.FindByNameAsync(normalizedRoleName)); }