public ActionResult Submit(Course course) { ScheduleDal dal = new ScheduleDal(); LecturerDal lecturerDal = new LecturerDal(); CourseDal courseDal = new CourseDal(); if (!lecturerDal.IsFound(course.Lecturer)) { ViewBag.error = " the lecturer is not found"; return(View("AddCourse")); } if (ModelState.IsValid) { try { Session["shid"] = (dal.schedules.Count() + 1).ToString(); course.shid = Session["shid"].ToString(); courseDal.courses.Add(course); courseDal.SaveChanges(); return(RedirectToAction("addschule")); } catch (Exception) { ViewBag.error1 = "Enter another course number"; return(View("AddCourse")); } //throw; } else { // ViewData["error1"] = "Enter another course number"; ViewBag.error1 = "Enter another course number"; } return(View("AddCourse")); //if(ModelState.IsValid) // return View(Content("HI EVERY THING IS OK BYBY")); //else //{ // return RedirectToAction("AddCourse"); //} //return View("ShowUsers"); // } }
public ActionResult SubmitCourse(Course course) { List <Course> courses = (from x in Coursedal.Courses select x).ToList <Course>(); if (course.MoedA >= course.MoedB) { ViewBag.messageError = "The Moed B exam can not take place before Moed A"; return(View("AddCourse", course)); } if (course.MoedA.Year < 2020 || course.MoedA.Year > 2021) { ViewBag.messageError = "Can not except years before 2020 or above 2021 " + "-" + course.MoedA.Year; return(View("AddCourse", course)); } if (course.MoedB.Year < 2020 || course.MoedB.Year > 2021) { ViewBag.messageError = "Can not except years before 2020 or above 2021 " + "-" + course.MoedB.Year; return(View("AddCourse", course)); } foreach (Course cs in courses) { if (course.CourseId == cs.CourseId) { ViewBag.messageError = "Course id" + course.CourseId + " already exist!"; return(View("AddCourse", course)); } if (course.CourseName == cs.CourseName && course.CourseId != cs.CourseId) { if (course.MoedA != cs.MoedA || course.MoedB != cs.MoedB) { ViewBag.messageError = "The dates of exams in course " + course.CourseName + " " + course.CourseId + " must be equals to the dates of course " + cs.CourseName + " " + cs.CourseId; return(View("AddCourse", course)); } } if (course.MoedA.Date == cs.MoedA.Date && (course.MoedA.Hour >= cs.MoedA.Hour && course.MoedA.Hour <= cs.MoedA.Hour + 3) && course.ExamAClass == cs.ExamAClass) { ViewBag.messageError = "The class " + cs.ExamAClass + " is already occupied between " + cs.MoedA + " to " + cs.MoedA.AddHours(3); return(View("AddCourse", course)); } if (course.MoedA.Date == cs.MoedB.Date && (course.MoedA.Hour >= cs.MoedB.Hour && course.MoedA.Hour <= cs.MoedB.Hour + 3) && course.ExamAClass == cs.ExamBClass) { ViewBag.messageError = "The class " + cs.ExamBClass + " is already occupied between " + cs.MoedB + " to " + cs.MoedB.AddHours(3); return(View("AddCourse", course)); } if (course.MoedB.Date == cs.MoedA.Date && (course.MoedB.Hour >= cs.MoedA.Hour && course.MoedB.Hour <= cs.MoedA.Hour + 3) && course.ExamBClass == cs.ExamAClass) { ViewBag.messageError = "The class " + cs.ExamAClass + " is already occupied between " + cs.MoedA + " to " + cs.MoedA.AddHours(3); return(View("AddCourse", course)); } if (course.MoedB.Date == cs.MoedB.Date && (course.MoedB.Hour >= cs.MoedB.Hour && course.MoedB.Hour <= cs.MoedB.Hour + 3) && course.ExamBClass == cs.ExamBClass) { ViewBag.messageError = "The class " + cs.ExamBClass + " is already occupied between " + cs.MoedB + " to " + cs.MoedB.AddHours(3); return(View("AddCourse", course)); } if (TimeCheck(course) == false) { ViewBag.messageError = "The start time " + course.LectureStart + " must be before end time " + course.LectureEnd; return(View("AddCourse", course)); } if (CheckDuplicateClassroom(course, cs) == false) { ViewBag.messageError = "The class " + cs.Classroom + " is already occupied between " + cs.LectureStart + " to " + cs.LectureEnd + " in " + cs.LectuerDay; return(View("AddCourse", course)); } if (CheckDuplicateLecturer(course, cs) == false) { ViewBag.messageError = cs.LecturerName + " is already teaching between " + cs.LectureStart + " to " + cs.LectureEnd + " in " + cs.LectuerDay; return(View("AddCourse", course)); } } if (ModelState.IsValid) { Coursedal.Courses.Add(course); Coursedal.SaveChanges(); ViewBag.message1 = "Course " + course.CourseName + " successfully added"; return(View("AdminHome")); } else { return(View("AddCourse", course)); } }