Esempio n. 1
0
 public async Task<IActionResult> AddClientClaim([FromRoute]string clientId, [FromBody]CreateClaimRequest request) {
     var client = await _configurationDbContext.Clients.SingleOrDefaultAsync(x => x.ClientId == clientId);
     if (client == null) {
         return NotFound();
     }
     var claimToAdd = new ClientClaim {
         Client = client,
         ClientId = client.Id,
         Type = request.Type,
         Value = request.Value
     };
     client.Claims = new List<ClientClaim> {
         claimToAdd
     };
     await _configurationDbContext.SaveChangesAsync();
     return Created(string.Empty, new ClaimInfo {
         Id = claimToAdd.Id,
         Type = claimToAdd.Type,
         Value = claimToAdd.Value
     });
 }
Esempio n. 2
0
        public async Task <IActionResult> AddUserClaim([FromRoute] string userId, [FromBody] CreateClaimRequest request)
        {
            var user = await _dbContext.Users.AsNoTracking().SingleOrDefaultAsync(x => x.Id == userId);

            if (user == null)
            {
                return(NotFound());
            }
            var claimToAdd = new IdentityUserClaim <string> {
                UserId     = userId,
                ClaimType  = request.Type,
                ClaimValue = request.Value
            };

            _dbContext.UserClaims.Add(claimToAdd);
            await _dbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetUserClaim), Name, new { userId, claimId = claimToAdd.Id }, new ClaimInfo {
                Id = claimToAdd.Id,
                Type = claimToAdd.ClaimType,
                Value = claimToAdd.ClaimValue
            }));
        }