Ejemplo n.º 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            [RequestBodyType(typeof(PostAssignRoleRequest), "post revoke role")] PostRevokeRoleRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                if (req.IsValid(out var validationResults))
                {
                    PostRevokeRoleResponse response = await _mediator.Send(req, cancellationToken);

                    return(new OkObjectResult(ResponseWrapper <PostRevokeRoleResponse, GroupServiceErrorCode> .CreateSuccessfulResponse(response)));
                }
                else
                {
                    return(new ObjectResult(ResponseWrapper <PostRevokeRoleResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.ValidationError, validationResults))
                    {
                        StatusCode = 422
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogErrorAndNotifyNewRelic($"Unhandled error in PostRevokeRole", ex);
                return(new ObjectResult(ResponseWrapper <PostCreateGroupResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Ejemplo n.º 2
0
        public async Task <GroupPermissionOutcome> PostRevokeRole(int userId, int groupId, GroupRoles role, int authorisedByUserID)
        {
            PostRevokeRoleRequest postRevokeRoleRequest = new PostRevokeRoleRequest()
            {
                AuthorisedByUserID = authorisedByUserID,
                GroupID            = groupId,
                UserID             = userId,
                Role = new RoleRequest()
                {
                    GroupRole = role
                }
            };

            var response = await PostAsync <BaseRequestHelpResponse <PostAssignRoleResponse> >($"/api/PostRevokeRole", postRevokeRoleRequest);

            if (response.HasContent && response.IsSuccessful)
            {
                return(response.Content.Outcome);
            }
            throw new Exception("Bad response from PostRevokeRole");
        }