Пример #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));
 }
Пример #2
0
 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));
 }
Пример #3
0
 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);
 }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
 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));
 }
Пример #7
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);
            }
        }
Пример #8
0
 protected virtual IdentityRoleClaim <TKey> CreateRoleClaim(IdentityRoleNav <TKey> role, Claim claim) => new IdentityRoleClaimNav <TKey>
 {
     RoleId     = role.Id,
     ClaimType  = claim.Type,
     ClaimValue = claim.Value
 };