public IActionResult Create(Aluno aluno) { //if (aluno?.Nome == null || aluno?.Email == null || aluno.Sexo == null) //{ // ViewBag.Erro = "Dados inválidos!"; // return View(); //} //else //{ //if (string.IsNullOrEmpty(aluno.Nome)) // ModelState.AddModelError("Nome","O nome é obrigatório"); //if (string.IsNullOrEmpty(aluno.Sexo)) // ModelState.AddModelError("Sexo", "O Sexo é obrigatório"); //if (string.IsNullOrEmpty(aluno.Email)) // ModelState.AddModelError("Email", "O Email é obrigatório"); //if (aluno.Nascimento <= DateTime.Now.AddYears(-18)) // ModelState.AddModelError("Nascimento", "Data de nascimento inválida"); if (!ModelState.IsValid) { return(View()); } else { //AlunoBLL _aluno = new AlunoBLL(); alunoBll.IncluirAluno(aluno); return(RedirectToAction("Index")); } }
public IActionResult Create(Aluno aluno) { if (ModelState.IsValid) { _alunoBll.IncluirAluno(aluno); return(RedirectToAction("Index")); } else { return(View()); } }
public IActionResult Create([FromForm] Aluno aluno) { if (!ModelState.IsValid) { return(View()); } else { AlunoBLL _aluno = new AlunoBLL(); _alunoBll.IncluirAluno(aluno); return(RedirectToAction("Index")); } }