public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)]
            [RequestBodyType(typeof(PutGroupMemberCredentialsRequest), "Put Group Member Credentials")] PutGroupMemberCredentialsRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                bool response = await _mediator.Send(req, cancellationToken);

                return(new OkObjectResult(ResponseWrapper <bool, GroupServiceErrorCode> .CreateSuccessfulResponse(response)));
            }
            catch (UnauthorisedException ex)
            {
                return(new ObjectResult(ResponseWrapper <bool, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.UnauthorisedError, "Unauthorised Error"))
                {
                    StatusCode = StatusCodes.Status401Unauthorized
                });
            }
            catch (Exception ex)
            {
                _logger.LogErrorAndNotifyNewRelic($"Unhandled error in PutGroupMemberCredentials", ex);
                return(new ObjectResult(ResponseWrapper <bool, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Exemplo n.º 2
0
        public async Task <bool> PutGroupMemberCredentials(PutGroupMemberCredentialsRequest putGroupMemberCredentialsRequest)
        {
            string              json     = JsonConvert.SerializeObject(putGroupMemberCredentialsRequest);
            StringContent       data     = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await Client.PutAsync("/api/PutGroupMemberCredentials", data);

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

            var deserialisedResponse = JsonConvert.DeserializeObject <ResponseWrapper <bool, GroupServiceErrorCode> >(str);

            if (deserialisedResponse.HasContent && deserialisedResponse.IsSuccessful)
            {
                return(deserialisedResponse.Content);
            }
            return(false);
        }
Exemplo n.º 3
0
        public async Task <bool> PutVolunteerCredential(string u, string g, string c, [FromBody] AssignCredentialsViewModel assignCredentialsViewModel, CancellationToken cancellationToken)
        {
            int targetUserId = Base64Utils.Base64DecodeToInt(u);
            int groupId      = Base64Utils.Base64DecodeToInt(g);
            int credentialId = Base64Utils.Base64DecodeToInt(c);

            var user = await _authService.GetCurrentUser(HttpContext, cancellationToken);

            DateTime?validUntil = assignCredentialsViewModel.ValidUntil == "Null" ? (DateTime?)null : DateTime.ParseExact(assignCredentialsViewModel.ValidUntil, DatePickerHelpers.DATE_PICKER_DATE_FORMAT, new CultureInfo("en-GB"));

            PutGroupMemberCredentialsRequest putGroupMemberCredentialsRequest = new PutGroupMemberCredentialsRequest()
            {
                AuthorisedByUserID = user.ID,
                UserId             = targetUserId,
                GroupId            = groupId,
                CredentialId       = credentialId,
                Reference          = assignCredentialsViewModel.Reference,
                Notes      = assignCredentialsViewModel.Notes,
                ValidUntil = validUntil,
            };

            return(await _groupMemberService.PutGroupMemberCredentials(putGroupMemberCredentialsRequest));
        }
Exemplo n.º 4
0
 public async Task <bool> PutGroupMemberCredentials(PutGroupMemberCredentialsRequest putGroupMemberCredentialsRequest)
 {
     return(await _groupRepository.PutGroupMemberCredentials(putGroupMemberCredentialsRequest));
 }