Exemplo n.º 1
0
        //only for seed(),on data validation here
        public int addCourseToStudents(String courseName, String studentName, int grade)
        {
            int             courseIndex     = courses.FindIndex(i => i.courseName == courseName);
            int             studentIndex    = students.FindIndex(i => i.name == studentName);
            CourseToStudent courseToStudent = new CourseToStudent(students[studentIndex], courses[courseIndex], grade);

            courseToStudents.Add(courseToStudent);
            return(0);
        }
Exemplo n.º 2
0
        //enroll a student in a course
        public int enrollStudent(String studentName, String courseName)
        {
            int studentIndex = students.FindIndex(i => i.name == studentName);
            int courseIndex  = courses.FindIndex(i => i.courseName == courseName);

            //check if the student adn course exist
            if (studentIndex == -1)
            {
                Console.WriteLine("Student " + studentName + " doesn't exist, please add the student first");
                return(-1);
            }
            if (courseIndex == -1)
            {
                Console.WriteLine("Course " + courseName + " doesn't exist, please add the course first");
                return(-1);
            }
            //check the credit limit
            List <CourseToStudent> result = courseToStudents.FindAll(i => (i.student.name == studentName));
            int currentCredit             = result.Sum(i => i.course.credit);
            int courseCredit = courses.Find(i => (i.courseName == courseName)).credit;

            if (currentCredit + courseCredit <= students[studentIndex].creditLimit)
            {
                //check the course max student limit
                int enrolledNumber = courseToStudents.FindAll(i => (i.course.courseName == courseName)).Count;
                if (courses[courseIndex].maxStudent >= (enrolledNumber + 1))
                {
                    CourseToStudent courseToStudent = new CourseToStudent(students[studentIndex], courses[courseIndex]);
                    courseToStudents.Add(courseToStudent);
                    return(0);
                }
                else
                {
                    Console.WriteLine("Coures " + courseName + "is going to exceed its max student limit ", courses[courseIndex].maxStudent);
                    return(-1);
                }
            }
            else
            {
                Console.WriteLine("Student " + studentName + "is going to exceed his/her credit limit", students[studentIndex].creditLimit);
                return(-1);
            }
        }