public async Task <IActionResult> Edit(int id, [Bind("Codigo,TurmaId,DisciplinaId,ProfessorId")] Disci_Turma disci_Turma) { CodTurma = disci_Turma.TurmaId; if (id != disci_Turma.Codigo) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(disci_Turma); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Disci_TurmaExists(disci_Turma.Codigo)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), new { id = disci_Turma.TurmaId })); } ViewData["DisciplinaId"] = new SelectList(_context.Disciplina.OrderBy(a => a.Nome), "Codigo", "Nome", disci_Turma.DisciplinaId); ViewData["ProfessorId"] = new SelectList(_context.Professor.OrderBy(a => a.Nome), "Codigo", "Nome", disci_Turma.ProfessorId); ViewData["TurmaId"] = new SelectList(_context.Turma.Where(d => d.Codigo == disci_Turma.TurmaId), "Codigo", "Nome"); return(View(disci_Turma)); }
public async Task <IActionResult> Create([Bind("Codigo,TurmaId,DisciplinaId,ProfessorId")] Disci_Turma disci_Turma) { //Para rodar os teste é necessario comentar o os atributos CodTurma CodTurma = disci_Turma.TurmaId; TempData.Keep("CodTurma"); if (ModelState.IsValid) { var _disci_Turma = _context.Disci_Tuma .Where(d => d.TurmaId == disci_Turma.TurmaId) .Where(d => d.DisciplinaId == disci_Turma.DisciplinaId) .ToListAsync(); if (_disci_Turma.Result.Count == 0) { _context.Add(disci_Turma); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { id = disci_Turma.TurmaId })); } ViewData["Falha"] = true; } ViewData["DisciplinaId"] = new SelectList(_context.Disciplina.OrderBy(a => a.Nome), "Codigo", "Nome", disci_Turma.DisciplinaId); ViewData["ProfessorId"] = new SelectList(_context.Professor.OrderBy(a => a.Nome), "Codigo", "Nome", disci_Turma.ProfessorId); ViewData["TurmaId"] = new SelectList(_context.Turma.Where(d => d.Codigo == disci_Turma.TurmaId), "Codigo", "Nome"); return(View(disci_Turma)); }