示例#1
0
        public async Task <LivroViewModel> CreateAsync(
            LivroAutorAggregateRequest livroAutorAggregateRequest)
        {
            var httpResponseMessage = await _httpClient
                                      .PostAsJsonAsync(string.Empty, livroAutorAggregateRequest);

            var contentStream = await httpResponseMessage.Content.ReadAsStreamAsync();

            var livroResponse = await JsonSerializer
                                .DeserializeAsync <LivroViewModel>(
                contentStream,
                new JsonSerializerOptions
            {
                IgnoreNullValues            = true,
                PropertyNameCaseInsensitive = true
            });

            return(livroResponse);
        }
示例#2
0
        public async Task <IActionResult> Create(
            LivroAutorCreateViewModel livroAutorCreateViewModel)
        {
            if (ModelState.IsValid)
            {
                var livroAutorAggregateViewModel =
                    new LivroAutorAggregateRequest(livroAutorCreateViewModel);

                await _livroHttpClient.CreateAsync(livroAutorAggregateViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            var autores = await _autorHttpClient.GetAllAsync();

            ViewData["AutorId"] = new SelectList(
                autores,
                nameof(AutorViewModel.Id),
                nameof(AutorViewModel.NomeCompletoId),
                livroAutorCreateViewModel.AutorId);
            return(View(livroAutorCreateViewModel));
        }