public async Task <IActionResult> Edit(int id, [Bind("Id, DataMatricula")] Matricula matricula, [Bind("IdTurma")] int IdTurma, [Bind("IdAluno")] int IdAluno) { if (id != matricula.Id) { return(NotFound()); } if (ModelState.IsValid) { try { matricula.Aluno = _context.Alunos.Where(a => a.Id == IdAluno).FirstOrDefault(); matricula.Turma = _context.Turmas.Where(t => t.Id == IdTurma).FirstOrDefault(); _context.Update(matricula); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MatriculaExists(matricula.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(matricula)); }
public async Task <IActionResult> Edit(int id, [Bind("Id, Sala")] Turma turma, [Bind("IdProfessor")] int IdProfessor) { if (id != turma.Id) { return(NotFound()); } if (ModelState.IsValid) { try { turma.Professor = _context.Professores.Where(p => p.Id == IdProfessor).FirstOrDefault(); _context.Update(turma); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProfessorExists(turma.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(turma)); }
public async Task <IActionResult> Create([Bind("Id,Nome,Email,DataNascimento,DataCadastro,Matricula,Ativo")] Alunos alunos) { if (ModelState.IsValid) { _context.Add(alunos); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(alunos)); }
public async Task <ActionResult> post(Curso model) { if (ModelState.IsValid) { _context.Curso.Add(model); await _context.SaveChangesAsync(); return(Created($"/api/curso/{model.codCurso}", model)); } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> put(int AlunoId, Aluno dadosAlunoAlt) { try { //verifica se existe aluno a ser alterado var result = await _context.Aluno.FindAsync(AlunoId); if (AlunoId != result.Id) { return(BadRequest()); } result.RA = dadosAlunoAlt.RA; result.Nome = dadosAlunoAlt.Nome; result.codCurso = dadosAlunoAlt.codCurso; await _context.SaveChangesAsync(); return(Created($"/api/aluno/{dadosAlunoAlt.RA}", dadosAlunoAlt)); } catch { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no acesso ao banco de dados.")); } }