public ActionResult EditPost(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CourseDate lessonToUpdate = lessonB.FindLesson(id); DateTime firstCourse = lessonB.FirstCourseDate(lessonToUpdate.CourseID); if (TryUpdateModel(lessonToUpdate, "", new string[] { "FirstCourse", "Day", "StartHour", "Duration" }) && (firstCourse == default(DateTime) || firstCourse == lessonToUpdate.FirstCourse)) { try { lessonB.SaveDataBase(); return(RedirectToAction("Index")); } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } if (firstCourse != default(DateTime) && firstCourse != lessonToUpdate.FirstCourse) { ModelState.AddModelError("", "This course already have first date course : " + firstCourse.ToString("d")); PopulateCourseDropDownList(lessonToUpdate.CourseDateID); return(View(lessonToUpdate)); } PopulateCourseDropDownList(lessonToUpdate.CourseDateID); return(View(lessonToUpdate)); }