public async Task <IActionResult> Directors([FromBody] NewDirectorsRequestDto dto)
        {
            User user;

            using (var client = new HttpClient())
            {
                var accessToken = await HttpContext.GetTokenAsync("access_token");

                client.SetBearerToken(accessToken);
                var response = await client.GetAsync("https://localhost:5001/connect/userinfo");

                if (response.IsSuccessStatusCode)
                {
                    user = await response.Content.ReadAsAsync <User>();
                }
                else
                {
                    return(Unauthorized());
                }
            }

            if (dto.Directors.Count > 1)
            {
                return(Ok(await _privateEntityService.InsertDirectors(user.Sub, dto)));
            }
            return(BadRequest("A minimum of two directors is required"));
        }
        public async Task <ApplicationResponseDto> InsertDirectors(Guid user, NewDirectorsRequestDto dto)
        {
            var application = await GetPrivateEntityApplicationAsync(user, dto.ApplicationId);

            application.PrivateEntity.Directors = _mapper.Map <List <Director> >(dto.Directors);
            return(await ReturnApplicationResponse(application));
        }
Ejemplo n.º 3
0
 public async Task <IActionResult> Directors(NewDirectorsRequestDto dto)
 {
     if (await _privateEntityApiClientService.NewDirectorsAsync(dto) != null)
     {
         return(Ok());
     }
     return(BadRequest("Something went wrong in saving Directors"));
 }
        public async Task <ApplicationResponseDto> NewDirectorsAsync(NewDirectorsRequestDto dto)
        {
            var response = await _client.PostAsJsonAsync("entity/directors", dto);

            if (response.IsSuccessStatusCode)
            {
                return(await response.Content.ReadAsAsync <ApplicationResponseDto>());
            }
            return(null);
        }