public ActionResult AddCourseSub(VMYourCourses c) { if (!Authorize()) { return(RedirectToAction("RedirectByUser", "Home")); } User currentUser = (User)Session["CurrentUser"]; c.course.userName = currentUser.UserName; if (ModelState.IsValid) { CoursesDal courseDal = new CoursesDal(); courseDal.courses.Add(c.course); courseDal.SaveChanges(); TempData["courseSuccessMsg"] = "קורס התווסף בהצלחה!"; } return(RedirectToAction("AddCourse")); }
public ActionResult ChangeLecturer(string CourseName, string LectID) { var LecturerDal = new LecturerDal(); var LecturerObj = (from x in LecturerDal.Lecturer select x).ToList <Lecturer>(); var FacultyDal = new FacultyDal(); var FacultyObj = (from x in FacultyDal.Faculty where x.ID.Equals(faculy_id) select x).ToList <Faculty>(); var CourseDal = new CoursesDal(); var CourseObj = (from x in CourseDal.Courses select x).ToList <Courses>(); var StudentsDal = new StudentsDal(); var StudentsObj = (from x in StudentsDal.Students select x).ToList <Student>(); Faculty faculty = new Faculty() { ID = faculy_id, FirstName = FacultyObj[0].FirstName, LastName = FacultyObj[0].LastName }; FacultyViewModel facultyViewModel = new FacultyViewModel() { faculty = faculty, Coursesdata = CourseObj, Studentsdata = StudentsObj, LecturersData = LecturerObj }; var CourseObj3 = (from x in CourseDal.Courses where x.LectID.Equals(LectID) select x).ToList <Courses>(); var CourseObj2 = (from x in CourseDal.Courses where x.CourseName.Equals(CourseName) select x).First <Courses>(); if (CourseObj2.LectID != LectID && CourseObj2 != null) { Courses c = new Courses() { CourseName = CourseObj2.CourseName, Classroom = CourseObj2.Classroom, Day = CourseObj2.Day, Hour = CourseObj2.Hour, MoedA = CourseObj2.MoedA, MoedB = CourseObj2.MoedB, LectID = LectID }; int cnt = 0; foreach (Courses c_2 in CourseObj3) { if (c_2.Day == c.Day && c_2.Hour == c.Hour) { cnt++; } } if (cnt == 0) { CourseDal.Courses.Remove(CourseObj2); CourseDal.Courses.Add(c); CourseDal.SaveChanges(); } else { ViewBag.ErrorMessage3 = "The course lecturer is already registered at this time"; return(View("Faculty", facultyViewModel)); } } return(View("Faculty", facultyViewModel)); }
public ActionResult EditCourse(string CourseName, string MoedA, string MoedB, string Day, string Hour, string Classroom) { var LecturerDal = new LecturerDal(); var LecturerObj = (from x in LecturerDal.Lecturer select x).ToList <Lecturer>(); var CourseDal = new CoursesDal(); var CourseObj2 = (from x in CourseDal.Courses where x.CourseName.Equals(CourseName) select x).First <Courses>(); var FacultyDal = new FacultyDal(); var FacultyObj = (from x in FacultyDal.Faculty where x.ID.Equals(faculy_id) select x).ToList <Faculty>(); var CoursesObj = (from x in CourseDal.Courses select x).ToList <Courses>(); var StudentsDal = new StudentsDal(); var StudentsObj = (from x in StudentsDal.Students select x).ToList <Student>(); Faculty faculty = new Faculty() { ID = faculy_id, FirstName = FacultyObj[0].FirstName, LastName = FacultyObj[0].LastName }; FacultyViewModel facultyViewModel = new FacultyViewModel() { faculty = faculty, Coursesdata = CoursesObj, Studentsdata = StudentsObj, LecturersData = LecturerObj }; Courses CourseObj = new Courses() { CourseName = CourseName, Day = Day, Hour = Hour, Classroom = Classroom, MoedA = MoedA, MoedB = MoedB, LectID = CourseObj2.LectID }; int cnt = 0; foreach (Courses c in CourseDal.Courses) { if (c.Day == CourseObj.Day && c.Hour == CourseObj.Hour && c.Classroom == CourseObj.Classroom) { cnt++; } } if (cnt == 1) { ViewBag.ErrorMessage = "The course lecturer is already registered at this time"; return(View("Faculty", facultyViewModel)); } else { CourseDal.Courses.Remove(CourseObj2); CourseDal.SaveChanges(); CourseDal.Courses.Add(CourseObj); CourseDal.SaveChanges(); } return(View("Faculty", facultyViewModel)); }
public ActionResult SubmitSchedule(Course course) { /* change course schedule */ if (ModelState.IsValid) { var id = Session["ID"].ToString(); /* change schedule grade */ using (CoursesDal coursesDb = new CoursesDal()) using (ExamsDal exmaDb = new ExamsDal()) using (UsersDal usersDb = new UsersDal()) using (GradesDal gradesDb = new GradesDal()) using (CourseParticipantsDal courseParticipantDb = new CourseParticipantsDal()) { /* check if course exist */ var courseId = coursesDb.Courses.Where(Course => Course.courseId.Equals(course.courseId)).FirstOrDefault(); if (courseId != null) { /* check if name is for course id */ /* check course name is the same in courses */ var courseName = coursesDb.Courses.Where(Course => Course.courseId.Equals(course.courseId) && Course.courseName.Equals(course.courseName)).FirstOrDefault(); if (courseName == null) { TempData["msg"] = "Invalid course Name"; return(View("ManageCourseSchedule", course)); } /* check lecturer exist */ var Lecturer = (from row in usersDb.Users where row.ID.Equals(course.lecturer) && row.type.Equals("Lecturer") select row).FirstOrDefault(); if (Lecturer == null) { TempData["msg"] = "Lecturer doesnt exist"; return(View("ManageCourseSchedule", course)); } /* check start time is before end time */ if (course.startTime >= course.endTime) { TempData["msg"] = "Course end time must be bigger than course start time"; return(View("ManageCourseSchedule", course)); } /* new time doesnt clash with students and lecturer schedule */ /* find students that take the course */ var studentThatTakeCourse = (from row in courseParticipantDb.CourseParticipants where row.courseId.Equals(course.courseId) select row.ID).ToList(); /* find all other courses students take */ var studentCourses = (from row in courseParticipantDb.CourseParticipants where studentThatTakeCourse.Contains(row.ID) && !row.courseId.Equals(course.courseId) select row.courseId).ToList(); /* get courses schedule + lecturer courses schedule */ var courses = (from row in coursesDb.Courses where studentCourses.Contains(row.courseId) || row.lecturer.Equals(course.lecturer) && !row.courseId.Equals(course.courseId) select row).ToList(); /* check no clashs between courses */ foreach (Course x in courses) { if (x.startTime < course.endTime && course.startTime < x.endTime && x.day.Equals(course.day)) { TempData["msg"] = "Course time clashes with student or lecturer schedule"; return(View("ManageCourseSchedule", course)); } } /* get all course with same class and check time doesnt clash */ courses = (from row in coursesDb.Courses where row.className.Equals(course.className) && !row.courseId.Equals(course.courseId) select row).ToList(); foreach (Course x in courses) { if (x.startTime < course.endTime && course.startTime < x.endTime && x.day.Equals(course.day)) { TempData["msg"] = "Course class clashes with other courses"; return(View("ManageCourseSchedule", course)); } } courseId.courseId = course.courseId; courseId.courseName = course.courseName; courseId.startTime = course.startTime; courseId.endTime = course.endTime; courseId.day = course.day; courseId.className = course.className; courseId.lecturer = course.lecturer; coursesDb.SaveChanges(); TempData["goodMsg"] = "Inserted\\updated course"; /* redirect with succsees message */ return(View("ManageCourseSchedule", new Course())); } /* if course doesnt exist */ else { /* check lecturer exist */ var Lecturer = (from row in usersDb.Users where row.ID.Equals(course.lecturer) && row.type.Equals("Lecturer") select row).FirstOrDefault(); if (Lecturer == null) { TempData["msg"] = "Lecturer doesnt exist"; return(View("ManageCourseSchedule", course)); } /* check start time is before end time */ if (course.startTime >= course.endTime) { TempData["msg"] = "Course end time must be bigger than course start time"; return(View("ManageCourseSchedule", course)); } /* new time doesnt clash with lecturers schedule */ /* get lecturer courses schedule */ var courses = (from row in coursesDb.Courses where row.lecturer.Equals(course.lecturer) select row).ToList(); /* check no clashs between courses */ foreach (Course x in courses) { if (x.startTime < course.endTime && course.startTime < x.endTime && x.day.Equals(course.day)) { TempData["msg"] = "Course time clashes with lecturer schedule"; return(View("ManageCourseSchedule", course)); } } /* get all course with same class and check time doesnt clash */ courses = (from row in coursesDb.Courses where row.className.Equals(course.className) select row).ToList(); foreach (Course x in courses) { if (x.startTime < course.endTime && course.startTime < x.endTime && x.day.Equals(course.day)) { TempData["msg"] = "Course class clashes with other courses"; return(View("ManageCourseSchedule", course)); } } coursesDb.Courses.Add(course); coursesDb.SaveChanges(); TempData["goodMsg"] = "Inserted\\updated course"; /* redirect with succsees message */ return(View("ManageCourseSchedule", new Course())); } } } else { return(View("ManageCourseSchedule", course)); } }
public ActionResult AddCourses(Courses obj)//send info to db { CoursesDal dal = new CoursesDal(); //list of all the courses List <Courses> CoursesObj = (from c in dal.courses select c).ToList <Courses>(); List <Courses> LecturersCourses = (from c in dal.courses where c.LecturerId.Contains(obj.LecturerId) select c).ToList <Courses>(); foreach (Courses lect in LecturersCourses) { List <Courses> Crs = (from c in CoursesObj where c.CourseId.Contains(lect.CourseId) select c).ToList <Courses>(); //Courses crss = dal.courses.Find(obj.CourseName); foreach (Courses c in Crs) { if (c.Day == obj.Day) { if (System.Convert.ToDecimal(c.StartHour) >= System.Convert.ToDecimal(obj.StartHour) && System.Convert.ToDecimal(c.StartHour) <= System.Convert.ToDecimal(obj.EndHour) || System.Convert.ToDecimal(c.EndHour) >= System.Convert.ToDecimal(obj.StartHour) && System.Convert.ToDecimal(c.EndHour) <= System.Convert.ToDecimal(obj.EndHour)) { return(RedirectToAction("ErrorPageAddCourse")); } } } } // CoursesDal dal = new CoursesDal(); if (dal.courses.Find(obj.CourseId) != null) { return(RedirectToAction("ErrorPage")); } //Courses cr = new Courses(); Courses courses = new Courses() { CourseName = obj.CourseName, CourseId = obj.CourseId, LecturerId = obj.LecturerId, ClassRoom = obj.ClassRoom, Day = obj.Day, Hours = obj.Hours, StartHour = obj.StartHour, EndHour = obj.EndHour }; //CoursesDal dal = new CoursesDal(); if (ModelState.IsValid) { try { dal.courses.Add(obj); dal.SaveChanges(); } catch (Exception) { TempData["error"] = "The course already exist!\n"; // print error message return(View()); } } return(RedirectToAction("Home")); }
public ActionResult Edit(string id, FormCollection collection)//---> gets course id, delete the row of it and add new row with changes from the faculty { CoursesDal dalC = new CoursesDal(); StudentsDal dalS = new StudentsDal(); string x = collection["LecturerId"]; string day = collection["Day"]; string StartHour = collection["StartHour"]; string EndHour = collection["EndHour"]; //list of all the courses List <Courses> CoursesObj = (from c in dalC.courses select c).ToList <Courses>(); List <Courses> LecturersCourses = (from c in dalC.courses where c.LecturerId.Contains(x) select c).ToList <Courses>(); //----------check if the lecturer has another course in this time foreach (Courses lect in LecturersCourses) { List <Courses> Crs = (from c in CoursesObj where c.CourseId.Contains(lect.CourseId) select c).ToList <Courses>(); //Courses crss = dal.courses.Find(obj.CourseName); foreach (Courses c in Crs) { if (c.Day == day) { if (System.Convert.ToDecimal(c.StartHour) >= System.Convert.ToDecimal(StartHour) && System.Convert.ToDecimal(c.StartHour) <= System.Convert.ToDecimal(EndHour) || System.Convert.ToDecimal(c.EndHour) >= System.Convert.ToDecimal(StartHour) && System.Convert.ToDecimal(c.EndHour) <= System.Convert.ToDecimal(EndHour)) { return(RedirectToAction("ErrorPageAddCourse")); } } } } //----------End check //----------check if there is a student with another course in this time List <Students> studentsCourses = (from s in dalS.students select s).ToList <Students>(); foreach (Students std in studentsCourses) { List <Courses> Crs = (from c in CoursesObj where c.CourseId.Contains(std.CourseName) select c).ToList <Courses>(); //Courses oneCourse = dalC.courses.Find(std.CourseName); foreach (Courses c in Crs) { if (c.Day == day) { if (System.Convert.ToDecimal(c.StartHour) >= System.Convert.ToDecimal(StartHour) && System.Convert.ToDecimal(c.StartHour) <= System.Convert.ToDecimal(EndHour) || System.Convert.ToDecimal(c.EndHour) >= System.Convert.ToDecimal(StartHour) && System.Convert.ToDecimal(c.EndHour) <= System.Convert.ToDecimal(EndHour)) { return(RedirectToAction("ErrorPageAddStud")); } } } } //CoursesDal dal = new CoursesDal(); Courses cr = dalC.courses.Find(id); dalC.courses.Remove(cr); dalC.SaveChanges(); Courses course = new Courses() { CourseName = collection["CourseName"], CourseId = collection["CourseId"], LecturerId = collection["LecturerId"], ClassRoom = collection["ClassRoom"], Day = collection["Day"], Hours = collection["Hours"], StartHour = collection["StartHour"], EndHour = collection["EndHour"] }; if (ModelState.IsValid) { try { (from c in dalC.courses where c.CourseName == id select c).ToList(); dalC.courses.Add(course); dalC.SaveChanges(); } catch (Exception) { TempData["error"] = "The course already exist!\n"; // print error message return(View()); } } return(View("Home")); }