public void AddLesson(LessonsVM lessonVM) { Lessons lesson = new Lessons { Day = lessonVM.Day, CourseID = lessonVM.CourseID, Duration = lessonVM.Duration, HourStart = lessonVM.HourStart, InstructorID = lessonVM.InstructorID }; db.Lessons.Add(lesson); db.SaveChanges(); }
public ActionResult Create(LessonsVM lessons) { try { if (ModelState.IsValid) { //Check Instructor can have only one coursesession of the same course List <Lessons> lessonsListe = new List <Lessons>(); lessonsListe = db.Lessons.ToList(); foreach (var item in lessonsListe) { if ((int)TempData["instructorId"] == item.InstructorID && lessons.CourseID == item.CourseID) { DropDownList(); TempData["instructorId"] = Session[SessionMessage.UserID]; ViewBag.ErrorMessage = ErrorMessages.ErrorMessageSameCourse; return(View()); } } //Check minimal duration of one coursesession if ((lessons.Duration) < 1) { DropDownList(); TempData["instructorId"] = Session[SessionMessage.UserID]; ViewBag.ErrorMessage = ErrorMessages.ErrorMessageNegativeTime; return(View()); } ////Check that the day of course is the same of the date start //if (lessons.Day.ToString() != lessons.DateTime.DayOfWeek.ToString()) //{ // DropDownList(); // TempData["instructorId"] = Session[SessionMessage.UserID]; // ViewBag.ErrorMessage = ErrorMessages.ErrorMessageNotSameDay; // return View(); //} lessons.InstructorID = (int)TempData["InstructorID"]; lessonB.AddLesson(lessons); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException /* dex */) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } DropDownList(lessons.ID); return(View(lessons)); }