public ActionResult EditStudent(string id, string course, FormCollection collection)//---> gets course name, delete the row of it and add new row with changes from the faculty
        {
            DateTime     now   = DateTime.Now;
            StudentsDal  dal   = new StudentsDal();
            ExamsDal     dalEx = new ExamsDal();
            Students     sd    = dal.students.Find(id, course);
            List <Exams> ex    = (from x in dalEx.exams
                                  where x.CourseId.Contains(sd.CourseName)
                                  select x).ToList <Exams>();

            foreach (Exams e in ex)
            {
                DateTime MoedADate = DateTime.Parse(e.MoedADate);
                DateTime MoedBDate = DateTime.Parse(e.MoedBDate);
                int      resultA   = DateTime.Compare(MoedADate, now.Date);
                if (resultA > 0)
                {
                    return(RedirectToAction("ErrorPageAddGrade"));
                }
                int resultB = DateTime.Compare(MoedBDate, now.Date);
                if (resultB > 0)
                {
                    return(RedirectToAction("ErrorPageAddGrade"));
                }
            }
            dal.students.Remove(sd);
            dal.SaveChanges();

            Students stud = new Students()
            {
                FirstName  = collection["FirstName"],
                LastName   = collection["LastName"],
                Id         = collection["Id"],
                CourseName = collection["CourseName"],
                GradeMoedA = collection["GradeMoedA"],
                GradeMoedB = collection["GradeMoedB"],
                FinalGrade = collection["FinalGrade"]
            };

            if (ModelState.IsValid)
            {
                try
                {
                    (from s in dal.students
                     where s.Id == id
                     select s).ToList();
                    dal.students.Add(stud);
                    dal.SaveChanges();
                }
                catch (Exception)
                {
                    TempData["error"] = "The course already exist!\n"; // print error message
                    return(View());
                }
            }
            return(View("Home"));
        }
        public ActionResult EditExam(string id)//---> gets Exam Id and return all the info about it
        {
            ExamsDal     dalE     = new ExamsDal();
            List <Exams> objExams = (from x in dalE.exams
                                     where x.CourseId.Contains(id)
                                     select x).ToList <Exams>();
            Exams cvm = new Exams();

            cvm = objExams[0];
            return(View(cvm));
        }
        public ActionResult Exams()
        {
            /* check if user had logged in system */
            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 Exams */
            using (CourseParticipantsDal courseParticipantDb = new CourseParticipantsDal())
                using (ExamsDal examsDb = new ExamsDal())
                {
                    var id = Session["ID"].ToString();

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

                    /* get student Exams for all his courses sort by date and time */
                    var exams =
                        (from row in examsDb.Exams
                         where courses.Contains(row.courseId)
                         select row).OrderBy(x => x.date).ThenBy(y => y.startTime).ToList();

                    /* create Exam list model */
                    ExamList studentExams = new ExamList();
                    studentExams.exams = new List <Exam>();
                    foreach (Exam x in exams)
                    {
                        studentExams.exams.Add(x);
                    }
                    return(View(studentExams));
                }
        }
        public ActionResult EditExam(string id, FormCollection collection)//---> gets exam id, delete the row of it and add new row with changes from the faculty
        {
            ExamsDal dal = new ExamsDal();

            Exams ex = dal.exams.Find(id);

            dal.exams.Remove(ex);
            dal.SaveChanges();

            Exams exam = new Exams()
            {
                CourseName = collection["CourseName"],
                CourseId   = collection["CourseId"],
                MoedADate  = collection["MoedADate"],
                ClassA     = collection["ClassA"],
                HoursA     = collection["HoursA"],
                MoedBDate  = collection["MoedBDate"],
                ClassB     = collection["ClassB"],
                HoursB     = collection["HoursB"]
            };

            if (ModelState.IsValid)
            {
                try
                {
                    (from c in dal.exams
                     where c.CourseId == id
                     select c).ToList();
                    dal.exams.Add(exam);
                    dal.SaveChanges();
                }
                catch (Exception)
                {
                    TempData["error"] = "The course already exist!\n"; // print error message
                    return(View());
                }
            }
            return(View("Home"));
        }
        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()));
        }
Example #6
0
 public ActionResult StudentsJson(int id)
 {
     return(Content(ExamsDal.StringJson(id)));
 }
Example #7
0
 public ActionResult List(int id)
 {
     ViewBag.list = ExamsDal.List(id);
     return(View());
 }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="eb"></param>
 /// <returns></returns>
 public ActionResult Addexams(ExamsBox eb)
 {
     return(Content(ExamsDal.Add(eb)));
 }
Example #9
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));
            }
        }
Example #10
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));
            }
        }
Example #11
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));
            }
        }
Example #12
0
 /// <summary>
 /// 修改学生成绩
 /// </summary>
 /// <param name="studentscore">类型 ExamsBox</param>
 /// <returns>返回字符串,返回“1”则修改成功</returns>
 public ActionResult Edit(ExamsBox studentscore)
 {
     return(Content(ExamsDal.Edit(studentscore)));
 }
        public ActionResult ShowStudents()//---> display table of all the courses in DB
        {
            DateTime now   = DateTime.Now;
            ExamsDal dalEx = new ExamsDal();

            List <Students> sd       = new List <Students>();
            string          mainconn = ConfigurationManager.ConnectionStrings["StudentsDal"].ConnectionString;
            SqlConnection   sqlconn  = new SqlConnection(mainconn);
            string          sqlQuery = "select Students.FirstName, Students.LastName, Students.Id,  Students.CourseName, Students.GradeMoedA, Students.GradeMoedB, Students.FinalGrade From Students";

            SqlCommand     sqlcomm = new SqlCommand(sqlQuery, sqlconn);
            SqlDataAdapter sda     = new SqlDataAdapter(sqlcomm);
            DataTable      dt      = new DataTable();

            sda.Fill(dt);


            foreach (DataRow dr in dt.Rows)
            {
                Students std      = new Students();
                string   courseId = dr["CourseName"].ToString();

                std.FirstName  = dr["FirstName"].ToString();
                std.LastName   = dr["LastName"].ToString();
                std.Id         = dr["Id"].ToString();
                std.CourseName = dr["CourseName"].ToString();
                List <Exams> ex = (from x in dalEx.exams
                                   where x.CourseId.Contains(courseId)
                                   select x).ToList <Exams>();
                foreach (Exams e in ex)
                {
                    DateTime MoedADate = DateTime.Parse(e.MoedADate);
                    DateTime MoedBDate = DateTime.Parse(e.MoedBDate);
                    int      resultA   = DateTime.Compare(MoedADate, now.Date);
                    if (resultA > 0)
                    {
                        std.GradeMoedA = "Has not yet been done";
                    }
                    else
                    {
                        std.GradeMoedA = dr["GradeMoedA"].ToString();
                    }
                    int resultB = DateTime.Compare(MoedBDate, now.Date);
                    if (resultB > 0)
                    {
                        std.GradeMoedB = "Has not yet been done";
                    }
                    else
                    {
                        std.GradeMoedB = dr["GradeMoedB"].ToString();
                    }
                }

                if (System.Convert.ToDecimal(dr["GradeMoedA"].ToString()) == -1 && System.Convert.ToDecimal(dr["GradeMoedB"].ToString()) == -1)
                {
                    std.FinalGrade = "Has not yet been done";
                }
                else
                {
                    if (System.Convert.ToDecimal(dr["GradeMoedA"].ToString()) > -1 && System.Convert.ToDecimal(dr["GradeMoedB"].ToString()) == -1)
                    {
                        std.FinalGrade = dr["GradeMoedA"].ToString();
                    }
                    else
                    {
                        std.FinalGrade = dr["GradeMoedB"].ToString();
                    }
                }
                //std.GradeMoedA = dr["GradeMoedA"].ToString();
                //std.GradeMoedB = dr["GradeMoedB"].ToString();
                //std.FinalGrade = dr["FinalGrade"].ToString();

                sd.Add(std);
            }
            return(View(sd));
        }