public virtual async Task <IList <Claim> > GetClaimsAsync(IdentityRoleNav <TKey> role, CancellationToken cancellationToken = default) { ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } return(await RoleClaims.Where(rc => rc.RoleId.Equals(role.Id)).Select(c => new Claim(c.ClaimType, c.ClaimValue)).ToListAsync(cancellationToken)); }
public virtual Task <string> GetRoleNameAsync(IdentityRoleNav <TKey> role, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } return(Task.FromResult(role.Name)); }
public virtual Task SetRoleNameAsync(IdentityRoleNav <TKey> role, string roleName, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } role.Name = roleName; return(Task.CompletedTask); }
public virtual async Task <IdentityResult> DeleteAsync(IdentityRoleNav <TKey> role, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } await DataConnection.DeleteAsync(role); return(IdentityResult.Success); }
public virtual async Task <IdentityResult> UpdateAsync(IdentityRoleNav <TKey> role, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } role.ConcurrencyStamp = Guid.NewGuid().ToString(); await DataConnection.UpdateAsync(role); return(IdentityResult.Success); }
public virtual Task AddClaimAsync(IdentityRoleNav <TKey> role, Claim claim, CancellationToken cancellationToken = default) { ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } if (claim == null) { throw new ArgumentNullException(nameof(claim)); } RoleClaims.DataContext.Insert(CreateRoleClaim(role, claim)); return(Task.FromResult(false)); }
public virtual async Task RemoveClaimAsync(IdentityRoleNav <TKey> role, Claim claim, CancellationToken cancellationToken = default) { ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } if (claim == null) { throw new ArgumentNullException(nameof(claim)); } var claims = await RoleClaims.Where(rc => rc.RoleId.Equals(role.Id) && rc.ClaimValue == claim.Value && rc.ClaimType == claim.Type).ToListAsync(cancellationToken); foreach (var c in claims) { RoleClaims.DataContext.Delete(c); } }
protected virtual IdentityRoleClaim <TKey> CreateRoleClaim(IdentityRoleNav <TKey> role, Claim claim) => new IdentityRoleClaimNav <TKey> { RoleId = role.Id, ClaimType = claim.Type, ClaimValue = claim.Value };