Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        // 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);
            }
        }
Ejemplo n.º 3
0
 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));
 }