public virtual Task AddClaimAsync(Role role, Claim claim, CancellationToken cancellationToken = default) { ThrowIfDisposed(); role.CheakArgument(); claim.CheakArgument(); Context.RoleClaims.Add(CreateRoleClaim(role, claim)); return(Task.CompletedTask); }
/// <summary> /// Adds a claim to a role. /// </summary> /// <param name="role">The role to add the claim to.</param> /// <param name="claim">The claim to add.</param> /// <returns> /// The <see cref="Task"/> that represents the asynchronous operation, containing the <see cref="IdentityResult"/> /// of the operation. /// </returns> public virtual async Task <IdentityResult> AddClaimAsync(Role role, Claim claim) { ThrowIfDisposed(); var claimStore = GetClaimStore(); claim.CheakArgument(); role.CheakArgument(); await claimStore.AddClaimAsync(role, claim, CancellationToken); return(await UpdateRoleAsync(role)); }
public override async Task <IList <User> > GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); claim.CheakArgument(); return(await(from userclaims in UserClaims join user in Users on userclaims.UserId equals user.Id where userclaims.ClaimValue == claim.Value && userclaims.ClaimType == claim.Type select user).ToListAsync()); }
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); } }
public override async Task ReplaceClaimAsync(User user, Claim claim, Claim newClaim, CancellationToken cancellationToken = default) { ThrowIfDisposed(); user.CheakArgument(); claim.CheakArgument(); newClaim.CheakArgument(); var matchedClaims = await UserClaims.Where(uc => uc.UserId.Equals(user.Id) && uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToListAsync(); foreach (var matchedClaim in matchedClaims) { matchedClaim.ClaimValue = newClaim.Value; matchedClaim.ClaimType = newClaim.Type; } }
public virtual async Task <IdentityResult> AddClaimAsync(IdentityRole role, Claim claim, CancellationToken cancellationToken = default) { ThrowIfDisposed(); role.CheakArgument(); claim.CheakArgument(); var f2 = await DbEntitySet.AnyAsync(d => d.Id.Equals(role.Id)); if (f2) { var flag = await RoleClaims.AnyAsync(a => a.ClaimType.Equals(claim.Type) && a.ClaimValue.Equals(claim.Value) && a.RoleId.Equals(role.Id)); if (!flag) { RoleClaims.Add(CreateRoleClaim(role, claim)); return(await SaveChangesAsync(cancellationToken)); } } return(IdentityResult.Failed("已经存在该权限")); }
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)); }