public IActionResult AdicionarAluno(AlunoCadastro alunoCadastro) { var alunoCommand = _mapper.Map <CadastraAlunoCommand>(alunoCadastro); _mediator.Send(alunoCommand); return(Ok("Aluno cadastrado com sucesso!")); }
public async Task AdicionarAluno(AlunoCadastro alunoCadastro) { var result = await _apiNotification.AdicionarAluno(alunoCadastro); if (!result.IsSuccessStatusCode) { var content = await result.Content.ReadAsStringAsync(); throw new Exception(content); } }
public async Task <IActionResult> Create(AlunoCadastro alunoCadastro) { try { await _serviceAluno.AdicionarAluno(alunoCadastro); } catch (Exception ex) { var messages = JsonSerializer.Deserialize <IEnumerable <ErrorMessage> >(ex.Message); ViewBag["ERROR"] = messages; return(View()); } return(RedirectToAction(nameof(Index))); }
public async Task <HttpResponseMessage> AdicionarAluno(AlunoCadastro alunoCadastro) { using (HttpClient client = new HttpClient()) { var body = JsonSerializer.Serialize(alunoCadastro); var request = new HttpRequestMessage() { RequestUri = new Uri(uri), Method = HttpMethod.Post, Content = new StringContent(body, Encoding.UTF8, "application/json") }; var response = await client.SendAsync(request); return(response); } }