public async Task <IActionResult> Edit(int id, [Bind("Id")] PeriodStudent periodStudent) { if (id != periodStudent.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(periodStudent); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PeriodStudentExists(periodStudent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(periodStudent)); }
// GET: Students/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } PeriodStudent periodStudent = new PeriodStudent(); periodStudent = await _context.PeriodStudents.Where(w => w.Student.Id == id).FirstAsync(); PeriodStudentVM periodStudentVM = new PeriodStudentVM(); periodStudentVM.Id = periodStudent.Student.Id; periodStudentVM.Student = periodStudent.Student.Name; periodStudentVM.Period = periodStudent.Period.Name; if (periodStudent == null) { return(NotFound()); } ViewBag.Periods = _context.Periods.Select(s => new SelectListItem() { Selected = (s.Id == periodStudent.Period.Id), Text = s.Name, Value = s.Name }).ToList(); return(View(periodStudentVM)); }
public async Task <IActionResult> Create([Bind("Id")] PeriodStudent periodStudent) { if (ModelState.IsValid) { _context.Add(periodStudent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(periodStudent)); }