Ejemplo n.º 1
0
        public async Task <IActionResult> SetUserBlock([FromRoute] string userId, [FromBody] SetUserBlockRequest request)
        {
            var user = await _dbContext.Users.SingleOrDefaultAsync(x => x.Id == userId);

            if (user == null)
            {
                return(NotFound());
            }
            user.Blocked = request.Blocked;
            var result = await _userManager.UpdateAsync(user);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors.ToValidationProblemDetails()));
            }
            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SetUserBlock([FromRoute] string userId, [FromBody] SetUserBlockRequest request)
        {
            var user = await _dbContext.Users.SingleOrDefaultAsync(x => x.Id == userId);

            if (user == null)
            {
                return(NotFound());
            }
            user.Blocked = request.Blocked;
            var result = await _userManager.UpdateAsync(user);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors.AsValidationProblemDetails()));
            }
            // When blocking a user we need to make sure we also revoke all of his tokens.
            await _persistedGrantService.RemoveAllGrantsAsync(userId);

            return(NoContent());
        }