Exemple #1
0
 public IActionResult Create([Bind("Id,Nome,Sexo,Email,Nascimento")] Aluno aluno)
 {
     if (ModelState.IsValid)
     {
         _alunoContext.Add(aluno);
         _alunoContext.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View());
 }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Email,Rg")] Aluno aluno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aluno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aluno));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("Id,Titulo")] Curso curso)
        {
            if (ModelState.IsValid)
            {
                _context.Add(curso);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(curso));
        }
Exemple #4
0
        [ValidateAntiForgeryToken] // [Bind("Id,Curso,Aluno,Nota")]
        public async Task <IActionResult> Create([Bind("Id,Curso,Aluno,Nota")] Matricula matricula)
        {
            if (matricula.Aluno.AlunoId != null && matricula.Curso.CursoId != null && matricula.Nota != null)
            {
                Matricula _matricula = new Matricula()
                {
                    AlunoId = matricula.Aluno.AlunoId,
                    CursoId = matricula.Curso.CursoId,
                    Nota    = matricula.Nota,
                };
                _context.Add(_matricula);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            MatriculaViewModel viewModel = new MatriculaViewModel()
            {
                Aluno = new Aluno()
                {
                    AlunoId = matricula.Aluno.AlunoId
                },
                Curso = new Curso()
                {
                    CursoId = matricula.Curso.CursoId
                },
                Alunos = _context.Alunos.ToList(),
                Cursos = _context.Cursos.ToList(),
                Notas  = new List <Nota> {
                    Nota.A, Nota.B, Nota.C, Nota.D, Nota.F
                },
            };

            ViewBag.viewModel = viewModel;

            return(View(viewModel));
        }
Exemple #5
0
 public void add(Aluno aluno)
 {
     context.Add <Aluno>(aluno);
     context.SaveChanges();
 }