public async Task <ActionResult> AddApiResourceClaim([FromBody] ApiClaimDto claim) { if (claim.Type == string.Empty) { return(BadRequest()); } int newId = await this._configurationManagementService.AddApiResourceClaimAsync(claim); return(this.CreatedAtAction(nameof(this.ReturnApiResourceClaim), new { ApiClaimName = claim.ApiClaimName, id = newId, version = _apiVersion.ToString() }, claim)); }
public async Task <ActionResult> UpdateApiResourceClaim([FromBody] ApiClaimDto claim) { var currentIdentityResource = await this._configurationManagementService.ReturnApiResourceClaimAsync(claim.ApiClaimName, claim.Id); if (currentIdentityResource == null) { return(NotFound()); } await this._configurationManagementService.UpdateApiResourceClaimAsync(claim); return(NoContent()); }
public async Task <int> AddApiResourceClaimAsync(ApiClaimDto claim) { IdentityServer4.EntityFramework.Entities.ApiResourceClaim newclaim = new IdentityServer4.EntityFramework.Entities.ApiResourceClaim(); var entityResult = await this._configContext.ApiResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.ApiClaimName.ToLower()); newclaim.Type = claim.Type; newclaim.ApiResourceId = entityResult.Id; var result = await this._configContext.AddAsync(newclaim); await this._configContext.SaveChangesAsync(); claim.ApiClaimName = entityResult.Name; return(result.Entity.Id); }
public async Task UpdateApiResourceClaimAsync(ApiClaimDto claim) { var entityResult = await this._configContext.ApiResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.ApiClaimName.ToLower()); if (entityResult == null) { throw new Exception("Entity Not Found"); } var foundClaim = entityResult.UserClaims.FirstOrDefault(c => c.Id == claim.Id); if (foundClaim == null) { throw new Exception("Claim not found"); } foundClaim.Type = claim.Type; this._configContext.Update(foundClaim); await this._configContext.SaveChangesAsync(); }
public async Task RemoveClaimFromApiResourceAsync(ApiClaimDto claim, bool saveChanges) { var entityResult = await this._configContext.ApiResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.ApiClaimName.ToLower()); if (entityResult == null) { throw new Exception("Entity Not Found"); } var foundClaim = entityResult.UserClaims.FirstOrDefault(c => c.Id == claim.Id); if (foundClaim == null) { throw new Exception("Claim not found"); } this._configContext.Remove(foundClaim); if (saveChanges) { await this._configContext.SaveChangesAsync(); } }