Exemplo n.º 1
0
        public ActionResult Cadastrar(Aluno aluno)
        {
            if (ModelState.IsValid)
            {
                _alunoService.Cadastrar(aluno);
                return(RedirectToAction("Index", "Tarefa"));
            }

            ViewBag.Aluno = aluno;
            return(View("FormNovoAluno"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] AlunoFormViewModel model)
        {
            var result = await _alunoService.Cadastrar(_mapper.Map <Aluno>(model));

            if (result.IsValid)
            {
                return(Ok(_mapper.Map <AlunoViewModel>(result.Entity)));
            }

            return(BadRequest(result.Result));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Cadastrar([FromBody] Aluno aluno)
        {
            try
            {
                var resultado = await _alunoService.Cadastrar(aluno);

                return(Ok(Resultado <string> .OK(resultado)));
            }
            catch (ValidacaoException e)
            {
                return(Ok(Resultado <string> .Erro(e.Message)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 4
0
 public void Cadastrar(Aluno aluno)
 {
     _alunoService.Cadastrar(aluno);
 }