Exemple #1
0
 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));
 }
Exemple #2
0
        public async override Task <IList <Claim> > GetClaimsAsync(Role role, CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }

            return(await RoleClaims.Where(rc => rc.RoleId == role.Id).Select(c => new Claim(c.ClaimType, c.ClaimValue)).ToListAsync(cancellationToken));
        }
Exemple #3
0
        public async virtual Task RemoveClaimAsync(Role role, Claim claim, CancellationToken cancellationToken = default)
        {
            ThrowIfDisposed();
            role.CheakArgument();
            claim.CheakArgument();
            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.Remove(c);
            }
        }
Exemple #4
0
        public override async Task RemoveClaimAsync(IdentityRole <TKey> role, Claim claim, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            role.ThrowIfNull(nameof(role));
            claim.ThrowIfNull(nameof(claim));

            RoleClaims ??= (await RoleClaimsTable.GetClaimsAsync(role.Id)).ToList();
            var roleClaims = RoleClaims.Where(x => x.RoleId.Equals(role.Id) && x.ClaimType == claim.Type && x.ClaimValue == claim.Value);

            foreach (var roleCalim in roleClaims)
            {
                RoleClaims.Remove(roleCalim);
            }
        }
        /// <summary>
        /// Removes the <paramref name="claim"/> given from the specified <paramref name="role"/>.
        /// </summary>
        /// <param name="role">The role to remove the claim from.</param>
        /// <param name="claim">The claim to remove from the role.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
        /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
        public async virtual Task RemoveClaimAsync(Role role, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
        {
            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.Remove(c);
            }
        }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        public async virtual Task <IdentityResult> RemoveClaimAsync(IdentityRole role, Claim claim, CancellationToken cancellationToken = default)
        {
            ThrowIfDisposed();
            role.CheakArgument();
            claim.CheakArgument();
            var rolecasims = RoleClaims.Where(rc =>
                                              rc.RoleId.Equals(role.Id) &&
                                              rc.ClaimValue == claim.Value &&
                                              rc.ClaimType == claim.Type).Select(s => new IdentityRole()
            {
                Id = s.Id, EditedTime = s.EditedTime
            });

            AutoSaveChanges = false;
            foreach (var item in rolecasims)
            {
                item.IsDeleted = true;
                var delte = await DeleteAsync(item, default);
            }
            AutoSaveChanges = true;
            return(await SaveChangesAsync(cancellationToken));
        }
Exemple #8
0
 public async virtual Task <IList <Claim> > GetClaimsAsync(Role role, CancellationToken cancellationToken = default)
 {
     ThrowIfDisposed();
     role.CheakArgument();
     return(await RoleClaims.Where(rc => rc.RoleId.Equals(role.Id)).Select(c => new Claim(c.ClaimType, c.ClaimValue)).ToListAsync(cancellationToken));
 }