public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            [RequestBodyType(typeof(PostAddUserToDefaultGroupsRequest), "post add user to default groups")] PostAddUserToDefaultGroupsRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                if (req.IsValid(out var validationResults))
                {
                    PostAddUserToDefaultGroupsResponse response = await _mediator.Send(req, cancellationToken);

                    return(new OkObjectResult(ResponseWrapper <PostAddUserToDefaultGroupsResponse, GroupServiceErrorCode> .CreateSuccessfulResponse(response)));
                }
                else
                {
                    return(new ObjectResult(ResponseWrapper <PostAddUserToDefaultGroupsResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.ValidationError, validationResults))
                    {
                        StatusCode = 422
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogErrorAndNotifyNewRelic($"Unhandled error in PostAddUserToDefaultGroups", ex);
                return(new ObjectResult(ResponseWrapper <PostAddUserToDefaultGroupsResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Exemplo n.º 2
0
        public async Task <PostAddUserToDefaultGroupsResponse> PostAddUserToDefaultGroups(int userId)
        {
            PostAddUserToDefaultGroupsRequest postAddUserToDefaultGroupsRequest = new PostAddUserToDefaultGroupsRequest()
            {
                UserID = userId
            };
            string              json     = JsonConvert.SerializeObject(postAddUserToDefaultGroupsRequest);
            StringContent       data     = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await Client.PostAsync("/api/PostAddUserToDefaultGroups", data);

            string str = await response.Content.ReadAsStringAsync();

            var deserializedResponse = JsonConvert.DeserializeObject <ResponseWrapper <PostAddUserToDefaultGroupsResponse, GroupServiceErrorCode> >(str);

            if (deserializedResponse.HasContent && deserializedResponse.IsSuccessful)
            {
                return(deserializedResponse.Content);
            }
            return(null);
        }