예제 #1
0
        public async Task <IActionResult> UpdateClaim([FromRoute] int claimId, [FromBody] UpdateUserClaimRequest request)
        {
            var userId    = User.FindSubjectId();
            var userClaim = await _dbContext.UserClaims.SingleOrDefaultAsync(x => x.UserId == userId && x.Id == claimId);

            if (userClaim == null)
            {
                return(NotFound());
            }
            var claimType = await _dbContext.ClaimTypes.SingleOrDefaultAsync(x => x.Name == userClaim.ClaimType);

            if (claimType == null)
            {
                return(NotFound());
            }
            if (!claimType.UserEditable)
            {
                ModelState.AddModelError(nameof(claimType), $"Claim '{claimType.Name}' is not editable.");
                return(BadRequest(new ValidationProblemDetails(ModelState)));
            }
            userClaim.ClaimValue = request.ClaimValue;
            await _dbContext.SaveChangesAsync();

            return(Ok(new ClaimInfo {
                Id = userClaim.Id,
                Type = userClaim.ClaimType,
                Value = request.ClaimValue
            }));
        }
예제 #2
0
        public async Task <IActionResult> UpdateClaim([FromRoute] int claimId, [FromBody] UpdateUserClaimRequest request)
        {
            var userId    = User.FindSubjectId();
            var userClaim = await _dbContext.UserClaims.SingleOrDefaultAsync(x => x.UserId == userId && x.Id == claimId);

            if (userClaim == null)
            {
                return(NotFound());
            }
            userClaim.ClaimValue = request.ClaimValue;
            await _dbContext.SaveChangesAsync();

            return(Ok(new ClaimInfo {
                Id = userClaim.Id,
                Type = userClaim.ClaimType,
                Value = request.ClaimValue
            }));
        }