Exemple #1
0
        public List <Course> GetDepartmentCoursesByUserID(string userID)
        {
            if (userID == null)
            {
                throw new Exception("User ID cannot be null");
            }
            Department currentDepartment = this.GetDepartmentByUserID(userID);
            CourseDAL  courseDal         = new CourseDAL();

            return(courseDal.GetCoursesByDepartmentName(currentDepartment.Name));
        }
Exemple #2
0
        /// <summary>
        /// Gets the teacher by teacher id.
        /// </summary>
        /// <param name="teacherUIDCheck">The teacher uid to check.</param>
        /// <returns>A teacher with the given teacher UID</returns>
        public Teacher GetTeacherByCRN(int crn)
        {
            MySqlConnection dbConnection = DbConnection.GetConnection();

            using (dbConnection)
            {
                dbConnection.Open();

                var selectQuery =
                    "SELECT teachers.* FROM teachers, teacher_teaches_courses WHERE teacher_teaches_courses.courses_CRN = @CRN";

                using (MySqlCommand cmd = new MySqlCommand(selectQuery, dbConnection))
                {
                    cmd.Parameters.AddWithValue("@CRN", crn);
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        int teacherUIDOrdinal     = reader.GetOrdinal("uid");
                        int officeLocationOrdinal = reader.GetOrdinal("office_location");
                        int emailOrdinal          = reader.GetOrdinal("email");
                        int publicEmailOrdinal    = reader.GetOrdinal("public_email");
                        int phoneOrdinal          = reader.GetOrdinal("phone_number");

                        while (reader.Read())
                        {
                            var officeLocation = reader[officeLocationOrdinal] == DBNull.Value
                                ? default(string)
                                : reader.GetString(officeLocationOrdinal);
                            var email = reader[emailOrdinal] == DBNull.Value
                                ? default(string)
                                : reader.GetString(emailOrdinal);
                            var publicEmail = reader[publicEmailOrdinal] != DBNull.Value && reader.GetBoolean(publicEmailOrdinal);
                            var phone       = reader[phoneOrdinal] == DBNull.Value
                                ? default(string)
                                : reader.GetString(phoneOrdinal);
                            var teacherUID = reader[teacherUIDOrdinal] == DBNull.Value
                                ? default(string)
                                : reader.GetString(teacherUIDOrdinal);
                            CourseDAL     courseGetter       = new CourseDAL();
                            List <Course> currTeacherCourses = courseGetter.GetCoursesByTeacherID(teacherUID);
                            Teacher       currTeacher        = new Teacher(officeLocation, email, publicEmail, phone, currTeacherCourses, teacherUID);

                            return(currTeacher);
                        }
                    }
                }

                dbConnection.Close();
            }

            return(null);
        }
        public List <Transcript.StudentCourseReport> GetDegreeReport(string studentIDCheck)
        {
            DegreeProgramDAL programDAL      = new DegreeProgramDAL();
            String           degreeProgram   = programDAL.GetDegreeProgramByStudentID(studentIDCheck);
            CourseCollection requiredCourses = programDAL.GetCoursesByDegreeProgram(degreeProgram);
            DegreeProgram    program         = new DegreeProgram(degreeProgram, requiredCourses);
            StudentDAL       studentDal      = new StudentDAL();
            Student          student         = studentDal.GetStudentByStudentID(studentIDCheck);
            CourseDAL        courseDal       = new CourseDAL();
            List <Course>    coursesTaken    = courseDal.GetCoursesByStudentID(studentIDCheck);
            Transcript       transcript      = new Transcript(program, student, coursesTaken);
            CourseTimeDAL    courseTimeDal   = new CourseTimeDAL();

            foreach (var course in transcript.Courses)
            {
                char?      grade = studentDal.GetGradeByCourseAndStudentID(course.CRN, studentIDCheck);
                CourseTime time  = courseTimeDal.GetCourseTimeByCRN(course.CRN);
                Transcript.StudentCourseReport courseReport = new Transcript.StudentCourseReport(course, program, student, grade, time);
                transcript.CourseReports.Add(courseReport);
            }
            return(transcript.CourseReports);
        }
Exemple #4
0
        public CourseCollection GetCoursesByDegreeProgram(string degreeProgramName)
        {
            if (degreeProgramName == null)
            {
                throw new Exception("Degree name cannot be null");
            }
            MySqlConnection  dbConnection    = DbConnection.GetConnection();
            CourseCollection coursesRequired = new CourseCollection();

            using (dbConnection)
            {
                dbConnection.Open();

                var selectQuery =
                    "SELECT * FROM degree_requires_courses, degree_programs, courses WHERE degree_programs.degree_id = degree_requires_courses.degree_id AND degree_programs.name = @degree_program_name AND degree_programs.name = courses.course_name";

                using (MySqlCommand cmd = new MySqlCommand(selectQuery, dbConnection))
                {
                    cmd.Parameters.AddWithValue("@degree_program_name", degreeProgramName);
                    using (MySqlDataReader queryResultReader = cmd.ExecuteReader())
                    {
                        int CRNOrdinal = queryResultReader.GetOrdinal("CRN");

                        while (queryResultReader.Read())
                        {
                            int       crn            = queryResultReader[CRNOrdinal] == DBNull.Value ? default(int) : queryResultReader.GetInt32(CRNOrdinal);
                            CourseDAL courseDal      = new CourseDAL();
                            Course    courseRequired = courseDal.GetCourseByCRN(crn);
                            coursesRequired.Add(courseRequired);
                        }

                        return(coursesRequired);
                    }
                }
            }
        }