コード例 #1
0
        public IActionResult AdicionarAluno(AlunoCadastro alunoCadastro)
        {
            var alunoCommand = _mapper.Map <CadastraAlunoCommand>(alunoCadastro);

            _mediator.Send(alunoCommand);

            return(Ok("Aluno cadastrado com sucesso!"));
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        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);
            }
        }