public static async Task xAddClaimAsync <TContext, TRole, TKey, TRoleClaim>(this IIdentityRoleClaimStoreWithContext <TContext, TRole, TKey, TRoleClaim> store, TRole role, Claim claim, CancellationToken cancellationToken = default) where TContext : class, IIdentityContext//, IIdentityContext_WithUserAndRoleClaims<TKey> where TKey : IEquatable <TKey> where TRole : class, IIdentityRoleWithClaims <TKey> where TRoleClaim : class, IIdentityRoleClaim <TKey>, new() { store.ThrowIfCancelledRequestOrDisposedOrRoleNull(role, cancellationToken); if (claim == null) { throw new ArgumentNullException(nameof(claim)); } var rc = role.xCreateRoleClaim <TKey, TRoleClaim>(claim); await store.Context.DbInsertAsync(rc, cancellationToken); await Task.CompletedTask; }
// xTask RemoveClaimAsync(TRole role, Claim claim, CancellationToken cancellationToken = default); public static async Task xRemoveClaimAsync <TContext, TRole, TKey, TRoleClaim>(this IIdentityRoleClaimStoreWithContext <TContext, TRole, TKey, TRoleClaim> store, TRole role, Claim claim, CancellationToken cancellationToken = default) where TContext : class, IIdentityContext//, IIdentityContext_WithUserAndRoleClaims<TKey> where TKey : IEquatable <TKey> where TRole : class, IIdentityRoleWithClaims <TKey> where TRoleClaim : class, IIdentityRoleClaim <TKey> { store.ThrowIfCancelledRequestOrDisposedOrRoleNull(role, cancellationToken); if (claim == null) { throw new ArgumentNullException(nameof(claim)); } var claims = await store.Context.DbGetQueryable <TRoleClaim>().Where(rc => rc.RoleId.Equals(role.Id) && rc.ClaimValue == claim.Value && rc.ClaimType == claim.Type).xToListAsync(cancellationToken); foreach (var c in claims) { await store.Context.DbDeleteAsync(c); } }
public static async Task <IList <Claim> > xGetClaimsAsync <TContext, TRole, TKey, TRoleClaim>(this IIdentityRoleClaimStoreWithContext <TContext, TRole, TKey, TRoleClaim> store, TRole role, CancellationToken cancellationToken = default) where TContext : class, IIdentityContext//, IIdentityContext_WithUserAndRoleClaims<TKey> where TKey : IEquatable <TKey> where TRole : class, IIdentityRoleWithClaims <TKey> where TRoleClaim : class, IIdentityRoleClaim <TKey> { store.ThrowIfCancelledRequestOrDisposedOrRoleNull(role, cancellationToken); return(await store.Context.DbGetQueryable <TRoleClaim>().Where(rc => rc.RoleId.Equals(role.Id)).Select(c => new Claim(c.ClaimType, c.ClaimValue)).xToListAsync(cancellationToken)); }