public ActionResult Create([Bind(Include = "CursoID,Descricao")] Curso curso) { if (ModelState.IsValid) { db.Cursos.Add(curso); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(curso)); }
public ActionResult Create([Bind(Include = "MatriculaID,DataMatricula,CursoID,AlunoID")] Matricula matricula) { if (ModelState.IsValid) { db.Matriculas.Add(matricula); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AlunoID = new SelectList(db.Alunos, "ID", "Nome", matricula.AlunoID); ViewBag.CursoID = new SelectList(db.Cursos, "CursoID", "Descricao", matricula.CursoID); return(View(matricula)); }
public Aluno Post([FromBody] Aluno aluno) { _context.Alunos.Add(aluno); _context.SaveChanges(); return(aluno); }
public ActionResult Create([Bind(Include = "Nome,Sobrenome,DataMatricula")] Aluno aluno) { try { if (ModelState.IsValid) { db.Alunos.Add(aluno); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(aluno)); }