public ActionResult Create([Bind(Include = "CursoID,Descricao")] Curso curso)
        {
            if (ModelState.IsValid)
            {
                db.Cursos.Add(curso);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(curso));
        }
Example #2
0
        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));
        }
Example #3
0
        public Aluno Post([FromBody] Aluno aluno)
        {
            _context.Alunos.Add(aluno);
            _context.SaveChanges();

            return(aluno);
        }
Example #4
0
        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));
        }