public ActionResult Edit(AbsenceViewModel viewModel) { if (ModelState.IsValid) { var absence = db.Absences.FirstOrDefault(a => a.Id == viewModel.Id); absence.AbsenceDate = viewModel.AbsenceDate; absence.CourseTitle = viewModel.CourseTitle; absence.StudentFirstName = viewModel.StudentFirstName; absence.StudentLastName = viewModel.StudentLastName; absence.CourseId = viewModel.CourseId; absence.StudentId = viewModel.StudentId; db.SaveChanges(); return RedirectToAction("Index"); } return View(viewModel); }
// GET: Absence/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Absence absence = db.Absences.Find(id); if (absence == null) { return HttpNotFound(); } var viewModel = new AbsenceViewModel(); viewModel.AbsenceDate = absence.AbsenceDate.Date; viewModel.CourseTitle = absence.CourseTitle; viewModel.StudentFirstName = absence.StudentFirstName; viewModel.StudentLastName = absence.StudentLastName; viewModel.Id = absence.Id; viewModel.CourseId = absence.CourseId; viewModel.StudentId = absence.StudentId; return View(viewModel); }