コード例 #1
0
        public ActionResult Student(Account account)
        {
            var StudentsDal      = new StudentsDal();
            var username         = account.ID;
            var StudentsUser     = (from x in StudentsDal.Students where x.ID.Equals(username) select x).ToList <Student>();
            var StudentCourseDal = new StudentCourseDal();
            var studentCourseObj = (from x in StudentCourseDal.StudentCourses where x.StudentID.Equals(username) select x).ToList <StudentCourse>();

            var            CoursesDal   = new CoursesDal();
            List <Courses> CourseDetail = new List <Courses>();
            Courses        t            = new Courses();

            foreach (StudentCourse y in studentCourseObj)
            {
                t = (from x in CoursesDal.Courses where x.CourseName.Equals(y.CourseName) select x).FirstOrDefault <Courses>();
                CourseDetail.Add(t);
            }
            Student student = new Student()
            {
                ID        = account.ID,
                FirstName = StudentsUser[0].FirstName,
                LastName  = StudentsUser[0].LastName,
            };
            StudentViewModel studentViewModel = new StudentViewModel()
            {
                student        = student,
                courses        = CourseDetail,
                studentCourses = studentCourseObj
            };

            return(View(studentViewModel));
        }
コード例 #2
0
        public ActionResult Faculty(Account account)
        {
            string id = account.ID;

            faculy_id = id;
            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(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        = account.ID,
                FirstName = FacultyObj[0].FirstName,
                LastName  = FacultyObj[0].LastName
            };
            FacultyViewModel facultyViewModel = new FacultyViewModel()
            {
                faculty       = faculty,
                Coursesdata   = CourseObj,
                Studentsdata  = StudentsObj,
                LecturersData = LecturerObj
            };

            return(View(facultyViewModel));
        }
コード例 #3
0
        /// <summary>
        /// 得到视图所需的数据
        /// </summary>
        /// <returns>返回json格式的所有课程(courses)</returns>
        public ActionResult Get()
        {
            if ((string)Session["Power"] != "1")
            {
                return(Json("0"));
            }

            return(Json(CoursesDal.List(), JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public ActionResult CoursesStudentsGrades()
        {
            /* Show all data */
            /* check if user had logged in */
            if (Session["ID"] == null || Session["password"] == null || Session["type"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            /* check if user is lecturer type */
            else if (!Session["type"].Equals("Faculty"))
            {
                return(RedirectToAction("Home", Session["type"].ToString()));
            }

            CoursesStudentsGrades viewobj = new CoursesStudentsGrades();

            viewobj.courses = new List <Course>();
            viewobj.users   = new List <User>();
            viewobj.grades  = new List <Grade>();

            using (CoursesDal coursesDb = new CoursesDal())
                using (UsersDal usersDb = new UsersDal())
                    using (GradesDal gradesDb = new GradesDal())
                    {
                        /* get all courses */
                        var courses =
                            (from row in coursesDb.Courses
                             orderby row.courseId
                             select row).ToList();

                        foreach (Course x in courses)
                        {
                            viewobj.courses.Add(x);
                        }

                        /* get all students */
                        var users =
                            (from row in usersDb.Users
                             where row.type.Equals("Student")
                             select row).ToList();
                        foreach (User x in users)
                        {
                            viewobj.users.Add(x);
                        }

                        /* get all grades */
                        var grades =
                            (from row in gradesDb.Grades
                             select row);

                        foreach (Grade x in grades)
                        {
                            viewobj.grades.Add(x);
                        }
                        return(View(viewobj));
                    }
        }
コード例 #5
0
        public JsonResult Del(int id)
        {
            if ((string)Session["Power"] != "1")
            {
                return(Json("0"));
            }

            CoursesDal.Del(id);
            return(Json(CoursesDal.List()));
        }
コード例 #6
0
        public JsonResult Edit(Courses co)
        {
            if ((string)Session["Power"] != "1")
            {
                return(Json("0"));
            }

            CoursesDal.Edit(co);
            return(Json(CoursesDal.List()));
        }
コード例 #7
0
        public ActionResult Edit(string id)//--->Courses- gets course id and return all the info about it
        {
            CoursesDal     dalC       = new CoursesDal();
            List <Courses> objCourses = (from x in dalC.courses
                                         where x.CourseId.Contains(id)
                                         select x).ToList <Courses>();
            Courses cvm = new Courses();

            cvm = objCourses[0];
            return(View(cvm));
        }
コード例 #8
0
        public ActionResult StudentToCourse(string StudentID, string CourseName)
        {
            var LecturerDal      = new LecturerDal();
            var LecturerObj      = (from x in LecturerDal.Lecturer select x).ToList <Lecturer>();
            var StudentCourseDal = new StudentCourseDal();
            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
            };

            StudentCourse sc = new StudentCourse()
            {
                CourseName = CourseName,
                StudentID  = StudentID,
            };

            if (StudentCourseDal.StudentCourses.Find(sc.StudentID, sc.CourseName) == null)
            {
                StudentCourseDal.StudentCourses.Add(sc);
                StudentCourseDal.SaveChanges();
            }
            else
            {
                ViewBag.ErrorMessage2 = "This student is already assigned to this course!";
                return(View("Faculty", facultyViewModel));
            }
            return(View("Faculty", facultyViewModel));
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
        public ActionResult Schedule()
        {
            /* check if user had logged in */
            if (Session["ID"] == null || Session["password"] == null || Session["type"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            /* check if user is student type */
            else if (!Session["type"].Equals("Student"))
            {
                return(RedirectToAction("Home", Session["type"].ToString()));
            }

            /* get student Schedule */
            using (CourseParticipantsDal courseParticipantDb = new CourseParticipantsDal())
                using (CoursesDal coursesDb = new CoursesDal())
                {
                    var id = Session["ID"].ToString();

                    /* get student course id for all his courses */
                    var courseIds =
                        (from row in courseParticipantDb.CourseParticipants
                         where row.ID.Equals(id)
                         select row.courseId).ToList();

                    /* get all  student courses sorted by time */
                    var courses =
                        (from row in coursesDb.Courses
                         where courseIds.Contains(row.courseId)
                         orderby row.startTime
                         select row).ToList();

                    /* create Schedule model - all courses in each day */
                    Schedule studentSchedule = new Schedule();
                    studentSchedule.Sunday    = courses.Where(x => x.day.Equals("Sunday")).ToList();
                    studentSchedule.Monday    = courses.Where(x => x.day.Equals("Monday")).ToList();
                    studentSchedule.Tuesday   = courses.Where(x => x.day.Equals("Tuesday")).ToList();
                    studentSchedule.Wednesday = courses.Where(x => x.day.Equals("Wednesday")).ToList();
                    studentSchedule.Thursday  = courses.Where(x => x.day.Equals("Thursday")).ToList();
                    studentSchedule.Friday    = courses.Where(x => x.day.Equals("Friday")).ToList();
                    studentSchedule.Saturday  = courses.Where(x => x.day.Equals("Saturday")).ToList();
                    return(View(studentSchedule));
                }
        }
コード例 #11
0
        public ActionResult Lecturer(Account account)
        {
            string   id            = account.ID;
            var      CoursesDal    = new CoursesDal();
            var      CourseDetails = (from x in CoursesDal.Courses where x.LectID.Equals(id) select x).ToList <Courses>();
            var      LecturerDal   = new LecturerDal();
            var      LecturerUser  = (from x in LecturerDal.Lecturer where x.ID.Equals(id) select x).ToList <Lecturer>();
            Lecturer lecturer      = new Lecturer()
            {
                ID        = account.ID,
                FirstName = LecturerUser[0].FirstName,
                LastName  = LecturerUser[0].LastName
            };


            LecturerViewModel lecturerViewModel = new LecturerViewModel()
            {
                lecturer = lecturer,
                courses  = CourseDetails
            };

            return(View(lecturerViewModel));
        }
コード例 #12
0
        public ActionResult Schedule()
        {
            /* check if user had logged in */
            if (Session["ID"] == null || Session["password"] == null || Session["type"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            /* check if user is lecturer type */
            else if (!Session["type"].Equals("Lecturer"))
            {
                return(RedirectToAction("Home", Session["type"].ToString()));
            }

            /* get lecturer Schedule */
            using (CoursesDal coursesDb = new CoursesDal())
            {
                var id = Session["ID"].ToString();

                /* get all  lecturer courses sorted by time */
                var courses =
                    (from row in coursesDb.Courses
                     where row.lecturer.Equals(id)
                     orderby row.startTime
                     select row).ToList();

                /* create Schedule model - all courses in each day */
                Schedule studentExams = new Schedule();
                studentExams.Sunday    = courses.Where(x => x.day.Equals("Sunday")).ToList();
                studentExams.Monday    = courses.Where(x => x.day.Equals("Monday")).ToList();
                studentExams.Tuesday   = courses.Where(x => x.day.Equals("Tuesday")).ToList();
                studentExams.Wednesday = courses.Where(x => x.day.Equals("Wednesday")).ToList();
                studentExams.Thursday  = courses.Where(x => x.day.Equals("Thursday")).ToList();
                studentExams.Friday    = courses.Where(x => x.day.Equals("Friday")).ToList();
                studentExams.Saturday  = courses.Where(x => x.day.Equals("Saturday")).ToList();
                return(View(studentExams));
            }
        }
コード例 #13
0
        public ActionResult MyStudents(string courseIDInput = "")
        {
            /* check if user had logged in */
            if (Session["ID"] == null || Session["password"] == null || Session["type"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            /* check if user is lecturer type */
            else if (!Session["type"].Equals("Lecturer"))
            {
                return(RedirectToAction("Home", Session["type"].ToString()));
            }

            /* get all lecturer courses and studnt list per course */
            using (CoursesDal coursesDb = new CoursesDal())
                using (UsersDal usersDb = new UsersDal())
                    using (CourseParticipantsDal courseParticipantDb = new CourseParticipantsDal())
                    {
                        var id       = Session["ID"].ToString();
                        var courseId = coursesDb.Courses.Where(Course => Course.courseId.Equals(courseIDInput) && Course.lecturer.Equals(id)).FirstOrDefault();

                        /* get all lecturer courses */
                        var courses =
                            (from row in coursesDb.Courses
                             where row.lecturer.Equals(id)
                             select row).ToList();

                        /* creae students and courses model */
                        CoursesAndStudents obj = new CoursesAndStudents();

                        /* add courses to modal */
                        obj.Courses = new List <Course>();
                        foreach (Course x in courses)
                        {
                            obj.Courses.Add(x);
                        }

                        /* if course isnt empty */
                        if (courseId != null)
                        {
                            /* get all students id that are in the course */
                            var students =
                                (from row in courseParticipantDb.CourseParticipants
                                 where row.courseId.Equals(courseId.courseId)
                                 select row.ID).ToList();

                            /* get all students name */
                            var studentNames =
                                (from row in usersDb.Users
                                 where students.Contains(row.ID)
                                 select row).ToList();

                            /* create student list */
                            obj.users = new List <User>();
                            foreach (User x in studentNames)
                            {
                                obj.users.Add(x);
                            }

                            return(View(obj));
                        }

                        /* course id doesnt exist and course is empty */
                        else if (courseIDInput != "")
                        {
                            /* create empty list of stuendts and error message */
                            TempData["msg"] = "Invalid course ID";
                            obj.users       = new List <User>();
                            return(View(obj));
                        }

                        /* course id doesnt exist and course is empty */
                        else
                        {
                            /* create empty list of stuendts */
                            obj.users = new List <User>();
                            return(View(obj));
                        }
                    }
        }
コード例 #14
0
        public ActionResult InsertGrade()
        {
            Grade grade = new Grade();

            grade.courseId   = Request["courseId"].ToString();
            grade.courseName = Request["courseName"].ToString();
            grade.moed       = Request["moed"].ToString();
            grade.grade      = Int32.Parse(Request["grade"]);
            grade.ID         = Request["ID"].ToString();

            var id = Session["ID"].ToString();

            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 lecturer passes this course */
                                var courseId = coursesDb.Courses.Where(Course => Course.courseId.Equals(grade.courseId) && Course.lecturer.Equals(id)).FirstOrDefault();
                                if (courseId == null)
                                {
                                    TempData["msg"] = "Invalid course ID";
                                    return(View("InsertGrades", grade));
                                }

                                /* check course name is the same in courses */
                                var courseName = coursesDb.Courses.Where(Course => Course.courseId.Equals(grade.courseId) && Course.courseName.Equals(grade.courseName) && Course.lecturer.Equals(id)).FirstOrDefault();
                                if (courseName == null)
                                {
                                    TempData["msg"] = "Invalid course Name";
                                    return(View("InsertGrades", grade));
                                }

                                /* check exam date has passed */
                                var exam =
                                    (from row in exmaDb.Exams
                                     where row.courseId.Equals(courseId.courseId) && row.moed.Equals(grade.moed)
                                     select row).FirstOrDefault();

                                if (exam == null)
                                {
                                    TempData["msg"] = "No such exam in system";
                                    return(View("InsertGrades", grade));
                                }

                                if (DateTime.Compare(exam.date + exam.endTime, DateTime.Now) > 0)
                                {
                                    TempData["msg"] = "Exam did not occur yet";
                                    return(View("InsertGrades", grade));
                                }

                                /* check if student exist */
                                var student =
                                    (from row in usersDb.Users
                                     where row.ID.Equals(grade.ID)
                                     select row).FirstOrDefault();
                                if (exam == null)
                                {
                                    TempData["msg"] = "Student doesnt exist";
                                    return(View("InsertGrades", grade));
                                }
                                /* check if student takes this course */
                                var studentTakesCourse =
                                    (from row in courseParticipantDb.CourseParticipants
                                     where row.ID.Equals(grade.ID) && row.courseId.Equals(grade.courseId)
                                     select row).FirstOrDefault();
                                if (studentTakesCourse == null)
                                {
                                    TempData["msg"] = "Student doesnt take this course";
                                    return(View("InsertGrades", grade));
                                }

                                /* check if student has this course if true update else insert */
                                var gradeInDb =
                                    (from row in gradesDb.Grades
                                     where row.courseId.Equals(grade.courseId) && row.moed.Equals(grade.moed) && row.ID.Equals(grade.ID)
                                     select row).FirstOrDefault();
                                if (gradeInDb != null)
                                {
                                    gradeInDb.grade = grade.grade;
                                    gradesDb.SaveChanges();
                                }
                                else
                                {
                                    gradesDb.Grades.Add(grade);
                                    gradesDb.SaveChanges();
                                }
                            }

            TempData["goodMsg"] = "Inserted\\updated grade";
            /* redirect with succsees message */
            return(View("InsertGrades", new Grade()));
        }
コード例 #15
0
        public ActionResult Grades(string courseIDInput = "")
        {
            /* check if user had logged in */
            if (Session["ID"] == null || Session["password"] == null || Session["type"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            /* check if user is lecturer type */
            else if (!Session["type"].Equals("Lecturer"))
            {
                return(RedirectToAction("Home", Session["type"].ToString()));
            }


            using (CoursesDal coursesDb = new CoursesDal())
                using (GradesDal gradesDb = new GradesDal())
                {
                    var id       = Session["ID"].ToString();
                    var courseId = coursesDb.Courses.Where(Course => Course.courseId.Equals(courseIDInput) && Course.lecturer.Equals(id)).FirstOrDefault();


                    /* get all lecturer courses */
                    var courses =
                        (from row in coursesDb.Courses
                         where row.lecturer.Equals(id)
                         select row).ToList();

                    /* creae grades and courses model */
                    CoursesAndGrades obj = new CoursesAndGrades();

                    /* add courses to modal */
                    obj.courses = new List <Course>();
                    foreach (Course x in courses)
                    {
                        obj.courses.Add(x);
                    }

                    /* if course isnt empty */
                    if (courseId != null)
                    {
                        /* get all grades in the course */
                        var studentGrades =
                            (from row in gradesDb.Grades
                             where row.courseId.Equals(courseId.courseId)
                             select row).ToList();

                        obj.grades = new List <Grade>();
                        foreach (Grade x in studentGrades)
                        {
                            obj.grades.Add(x);
                        }

                        return(View(obj));
                    }

                    /* course id doesnt exist and course is not empty */
                    else if (courseIDInput != "")
                    {
                        /* create empty list of grades and error message */
                        TempData["msg"] = "Invalid course ID";
                        obj.grades      = new List <Grade>();
                        return(View(obj));
                    }

                    /* course id doesnt exist and course is empty */
                    else
                    {
                        /* create empty list of stuendts */
                        obj.grades = new List <Grade>();
                        return(View(obj));
                    }
                }
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        public ActionResult AddStudents(Students obj)//send info to db
        {
            StudentsDal dal  = new StudentsDal();
            CoursesDal  dalC = new CoursesDal();
            //list of of the same student and his courses
            List <Students> studentsCourses = (from s in dal.students
                                               where s.Id.Contains(obj.Id)
                                               select s).ToList <Students>();
            //list of all the courses
            List <Courses> CoursesObj = (from c in dalC.courses
                                         select c).ToList <Courses>();

            foreach (Students std in studentsCourses)
            {
                //only one course
                List <Courses> Crs = (from c in CoursesObj
                                      where c.CourseId.Contains(std.CourseName)
                                      select c).ToList <Courses>();
                Courses cr = dalC.courses.Find(obj.CourseName);
                foreach (Courses c in Crs)
                {
                    if (cr.Day == c.Day)
                    {
                        if (System.Convert.ToDecimal(cr.StartHour) >= System.Convert.ToDecimal(c.StartHour) &&
                            System.Convert.ToDecimal(cr.StartHour) <= System.Convert.ToDecimal(c.EndHour) ||
                            System.Convert.ToDecimal(cr.EndHour) >= System.Convert.ToDecimal(c.StartHour) &&
                            System.Convert.ToDecimal(cr.EndHour) <= System.Convert.ToDecimal(c.EndHour))
                        {
                            return(RedirectToAction("ErrorPageAddStud"));
                        }
                    }
                }
            }
            Students students = new Students()
            {
                FirstName  = obj.FirstName,
                LastName   = obj.LastName,
                Id         = obj.Id,
                CourseName = obj.CourseName,
                GradeMoedA = obj.GradeMoedA,
                GradeMoedB = obj.GradeMoedB,
                FinalGrade = obj.FinalGrade
            };

            //StudentsDal dal = new StudentsDal();

            if (ModelState.IsValid)
            {
                try
                {
                    dal.students.Add(obj);
                    dal.SaveChanges();
                }
                catch (Exception)
                {
                    TempData["error"] = "The course already exist!\n"; // print error message
                    return(View());
                }
            }
            return(RedirectToAction("Home"));
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        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"));
        }
コード例 #20
0
        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"));
        }
コード例 #21
0
        public ActionResult SubmitExam(Exam exam)
        {
            if (ModelState.IsValid)
            {
                /* change or add exam */
                using (CoursesDal coursesDb = new CoursesDal())
                    using (ExamsDal exmaDb = new ExamsDal())
                        using (CourseParticipantsDal courseParticipantDb = new CourseParticipantsDal())
                        {
                            /* check course exist */
                            var courseId = coursesDb.Courses.Where(Course => Course.courseId.Equals(exam.courseId)).FirstOrDefault();
                            if (courseId == null)
                            {
                                TempData["msg"] = "Invalid course ID";
                                return(View("ManageExams", exam));
                            }

                            /* check course name is the same in courses */
                            var courseName = coursesDb.Courses.Where(Course => Course.courseId.Equals(exam.courseId) && Course.courseName.Equals(exam.courseName)).FirstOrDefault();
                            if (courseName == null)
                            {
                                TempData["msg"] = "Invalid course Name";
                                return(View("ManageExams", exam));
                            }

                            /* check start time is before end time */
                            if (exam.startTime >= exam.endTime)
                            {
                                TempData["msg"] = "Exam end time must be bigger than Exam start time";
                                return(View("ManageExams", exam));
                            }

                            /* check date isnt in the past */
                            if (DateTime.Compare(exam.date + exam.startTime, DateTime.Now) < 0)
                            {
                                TempData["msg"] = "Exam cant be in the past";
                                return(View("ManageExams", exam));
                            }


                            /* get all exams with same class and check time doesnt clash */
                            var exams = (from row in exmaDb.Exams
                                         where row.className.Equals(exam.className)
                                         select row).ToList();

                            foreach (Exam x in exams)
                            {
                                if (x.startTime < exam.endTime && exam.startTime < x.endTime && x.date.Equals(exam.date))
                                {
                                    TempData["msg"] = "Exam class clashes with other Exams";
                                    return(View("ManageExams", exam));
                                }
                            }

                            /* check moed a is before b */
                            if (exam.moed == "A")
                            {
                                /* check if moed B exam exist */
                                var moedBExam =
                                    (from row in exmaDb.Exams
                                     where row.courseId.Equals(exam.courseId) && row.moed.Equals("B")
                                     select row).FirstOrDefault();

                                if (moedBExam != null)
                                {
                                    if (moedBExam.date <= exam.date)
                                    {
                                        TempData["msg"] = "Moed A needs to be before Moed B";
                                        return(View("ManageExams", exam));
                                    }
                                }
                            }

                            if (exam.moed == "B")
                            {
                                /* check if moed A exam exist */
                                var moedAExam =
                                    (from row in exmaDb.Exams
                                     where row.courseId.Equals(exam.courseId) && row.moed.Equals("A")
                                     select row).FirstOrDefault();

                                if (moedAExam != null)
                                {
                                    if (moedAExam.date >= exam.date)
                                    {
                                        TempData["msg"] = "Moed A needs to be before Moed B";
                                        return(View("ManageExams", exam));
                                    }
                                }
                            }


                            /* check if exam exist */
                            var examInDb =
                                (from row in exmaDb.Exams
                                 where row.courseId.Equals(exam.courseId) && row.moed.Equals(exam.moed)
                                 select row).FirstOrDefault();

                            /* if exam exsist update */
                            if (examInDb != null)
                            {
                                examInDb.courseId   = exam.courseId;
                                examInDb.courseName = exam.courseName;
                                examInDb.moed       = exam.moed;
                                examInDb.date       = exam.date;
                                examInDb.startTime  = exam.startTime;
                                examInDb.endTime    = exam.endTime;
                                examInDb.className  = exam.className;

                                exmaDb.SaveChanges();
                            }
                            /*else insert new exam */
                            else
                            {
                                exmaDb.Exams.Add(exam);
                                exmaDb.SaveChanges();
                            }

                            TempData["goodMsg"] = "Inserted\\updated exam";
                            /* redirect with succsees message */
                            return(View("ManageExams", new Exam()));
                        }
            }
            else
            {
                return(View("ManageExams", exam));
            }
        }
コード例 #22
0
        public ActionResult SubmitParticipant(CourseParticipant courseParticipant)
        {
            if (ModelState.IsValid)
            {
                /* add course to student */

                var id = Session["ID"].ToString();

                /* change or add 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 course exist */
                                    var courseId = coursesDb.Courses.Where(Course => Course.courseId.Equals(courseParticipant.courseId)).FirstOrDefault();
                                    if (courseId == null)
                                    {
                                        TempData["msg"] = "Invalid course ID";
                                        return(View("ManageCourseParticipants", courseParticipant));
                                    }

                                    /* check if student exist */
                                    var student =
                                        (from row in usersDb.Users
                                         where row.ID.Equals(courseParticipant.ID) && row.type.Equals("Student")
                                         select row).FirstOrDefault();
                                    if (student == null)
                                    {
                                        TempData["msg"] = "Student doesnt exist";
                                        return(View("ManageCourseParticipants", courseParticipant));
                                    }

                                    /* check if student takes this course */
                                    var studentTakesCourse =
                                        (from row in courseParticipantDb.CourseParticipants
                                         where row.ID.Equals(courseParticipant.ID) && row.courseId.Equals(courseParticipant.courseId)
                                         select row).FirstOrDefault();
                                    if (studentTakesCourse != null)
                                    {
                                        TempData["msg"] = "Student takes this course";
                                        return(View("ManageCourseParticipants", courseParticipant));
                                    }

                                    /* course time doesnt clashes with student courses */
                                    var studentCourses =
                                        (from row in courseParticipantDb.CourseParticipants
                                         where row.ID.Equals(courseParticipant.ID)
                                         select row.courseId).ToList();

                                    var courses =
                                        (from row in coursesDb.Courses
                                         where studentCourses.Contains(row.courseId)
                                         select row).ToList();


                                    foreach (Course x in courses)
                                    {
                                        if (x.startTime < courseId.endTime && courseId.startTime < x.endTime && x.day.Equals(courseId.day))
                                        {
                                            TempData["msg"] = "Course time clashes with student schedule";
                                            return(View("ManageCourseParticipants", courseParticipant));
                                        }
                                    }


                                    /* add course to student */
                                    courseParticipantDb.CourseParticipants.Add(courseParticipant);
                                    courseParticipantDb.SaveChanges();
                                }

                TempData["goodMsg"] = "Inserted\\updated grade";
                /* redirect with succsees message */
                return(View("ManageCourseParticipants", new CourseParticipant()));
            }
            else
            {
                return(View("ManageCourseParticipants", courseParticipant));
            }
        }
コード例 #23
0
        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));
            }
        }