// GET: Teacher/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var teacher = await teacherRepo.GetTeacherForId(id.Value); if (teacher == null) { return(NotFound()); } TeacherEducationsVM vm = new TeacherEducationsVM(educationRepo, teacher); return(View(vm)); }
// GET: Teacher/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(BadRequest());//standard taalafhankelijk browser Http Error 400 } var teacher = await _teacherRepo.GetForIdAsync(id.Value); if (teacher == null) { return(NotFound()); //Http Error 404 //Of: Zorg voor een customised error (zie verder) } IEnumerable <Education> SelectedEducations = await educationRepo.GetAllEducationsByTeacher(teacher.Id); TeacherEducationsVM vm = new TeacherEducationsVM(educationRepo, teacher, SelectedEducations); return(View(vm)); }
public async Task <ActionResult> Edit(int id, IFormCollection collection, TeacherEducationsVM vm) { try { // TODO: Add update logic here if (!ModelState.IsValid) { return(View(new TeacherEducationsVM(educationRepo, vm.Teacher))); } await teacherRepo.Update(vm.Teacher); teacherRepo.RemoveEducation(vm.Teacher.Id); teacherRepo.AddEducationsToTeacher(vm.Teacher.Id, vm.SelectedEducationsString); return(RedirectToAction(nameof(IndexAsync))); } catch (Exception ex) { return(View(new TeacherEducationsVM(educationRepo, vm.Teacher))); } }