Esempio n. 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
            [RequestBodyType(typeof(GetGroupMembersForGivenRoleRequest), "Get Group Members For Given Role")] GetGroupMembersForGivenRoleRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                if (req.IsValid(out var validationResults))
                {
                    GetGroupMembersForGivenRoleResponse response = await _mediator.Send(req, cancellationToken);

                    return(new OkObjectResult(ResponseWrapper <GetGroupMembersForGivenRoleResponse, GroupServiceErrorCode> .CreateSuccessfulResponse(response)));
                }
                else
                {
                    return(new ObjectResult(ResponseWrapper <GetGroupMembersForGivenRoleResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.ValidationError, validationResults))
                    {
                        StatusCode = 422
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogErrorAndNotifyNewRelic($"Unhandled error in GetGroupMembersForGivenRole", ex);
                return(new ObjectResult(ResponseWrapper <GetGroupMembersForGivenRoleResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Esempio n. 2
0
        public async Task <List <int> > GetGroupMembersForGivenRole(int groupID, GroupRoles groupRoles)
        {
            GetGroupMembersForGivenRoleRequest request = new GetGroupMembersForGivenRoleRequest()
            {
                AuthorisingUserID = -1,
                GroupId           = groupID,
                GroupRole         = new RoleRequest()
                {
                    GroupRole = groupRoles
                }
            };
            string path = $"/api/GetGroupMembersForGivenRole";

            using (HttpResponseMessage response = await _httpClientWrapper.GetAsync(HttpClientConfigName.GroupService, path, request, CancellationToken.None).ConfigureAwait(false))
            {
                string jsonResponse = await response.Content.ReadAsStringAsync();

                var getGroupMembersForGivenRoleResponse = JsonConvert.DeserializeObject <ResponseWrapper <GetGroupMembersForGivenRoleResponse, GroupServiceErrorCode> >(jsonResponse);
                if (getGroupMembersForGivenRoleResponse.HasContent && getGroupMembersForGivenRoleResponse.IsSuccessful)
                {
                    GetGroupMembersForGivenRoleResponse resp = getGroupMembersForGivenRoleResponse.Content;
                    return(resp.UserIDs);
                }
                return(null);
            }
        }