public static StudentCourse EnrollStudentView()
        {
            string consoleInput = "";
            int studentID, courseID;
            bool validStudentID, validCourseID = false;
            var studentCourse = new StudentCourse();

            Console.Clear();
            Console.WriteLine("Add Student to Course:");

            Console.Write("Student ID: ");
            consoleInput = Console.ReadLine();
            validStudentID = Int32.TryParse(consoleInput, out studentID);

            Console.Write("Course ID: ");
            consoleInput = Console.ReadLine();
            validCourseID = Int32.TryParse(consoleInput, out courseID);

            if (!validStudentID || !validCourseID)
            {
                Console.WriteLine("Invalid Student ID or Course ID");
                Console.Write("\nPress [Enter] key to continue... ");
                Console.ReadLine();
            }
            else
            {
                studentCourse.StudentID = studentID;
                studentCourse.CourseID = courseID;
            }
            return studentCourse;
        }
示例#2
0
        public static StudentCourse EnrollStudentView()
        {
            string ConsoleString = "";
            int StudentID, CourseID;
            bool ValidStudentID, ValidCourseID = false;
            var studentCourse = new StudentCourse();

            Console.Clear();
            Console.WriteLine("Add Student to Course:");

            Console.Write("Student ID: ");
            ConsoleString = Console.ReadLine();
            ValidStudentID = Int32.TryParse(ConsoleString, out StudentID);

            Console.Write("Course ID: ");
            ConsoleString = Console.ReadLine();
            ValidCourseID = Int32.TryParse(ConsoleString, out CourseID);

            if (!ValidStudentID || !ValidCourseID)
            {
                Console.WriteLine("Invalid Student ID or Course ID");
                Console.Write("\nPress [Enter] key to continue... ");
                Console.ReadLine();
            }
            else
            {
                studentCourse.StudentID = StudentID;
                studentCourse.CourseID = CourseID;
            }
            return studentCourse;
        }
示例#3
0
 public static void EnrollStudent(StudentCourse studentCourse)
 {
     if (studentCourse != null)
     {
         using (var context = new EFCoreRefContext())
         {
             Student student = context.Student.FirstOrDefault(s => s.ID == studentCourse.StudentID);
             Course course = context.Course.FirstOrDefault(c => c.ID == studentCourse.CourseID);
             if (student != null && course != null)
             {
                 //The student and course exist
                 StudentCourse CurrentStudentCourses = context.StudentCourse
                     .Where(sc => sc.StudentID == studentCourse.StudentID)
                     .Where(sc => sc.CourseID == studentCourse.CourseID)
                     .FirstOrDefault();
                 if (CurrentStudentCourses == null)
                 {
                     //The student isn't currently enrolled so we are good to add them to the course
                     context.StudentCourse.Add(studentCourse);
                     context.SaveChanges();
                 }
             }
         }
     }
 }
        public static void MenuHandler()
        {
            char MenuSelection;
            var course = new Course();

            do
            {
                MenuSelection = CourseMenu.Display();

                switch (MenuSelection)
                {
                    //List all courses
                    case '1':
                        var courses = new List<Course>();
                        courses = CourseManagement.List();
                        CourseView.ListCoursesView(courses);
                        break;
                    //List all students for a course
                    case '2':
                        course = null;
                        int courseID = CourseView.InputCourseIDView();
                        course = CourseManagement.GetCourseByID(courseID);
                        CourseView.ListStudentsEnrolledInCourse(course);
                        break;
                    //Add a course
                    case '3':
                        course = null;
                        course = CourseView.AddCourseView();
                        CourseManagement.AddCourse(course);
                        break;
                    //Enroll student in a course
                    case '4':
                        var studentCourse = new StudentCourse();
                        studentCourse = EnrollmentView.EnrollStudentView();
                        Enrollment.EnrollStudent(studentCourse);
                        break;
                    //Delete all courses
                    case '5':
                        if (CourseView.InputToDeleteAllView() == "y")
                        {
                            if (CourseView.InputAdminPasswordView() == "y")
                            {
                                CourseManagement.DeleteAll();
                                CourseView.DeleteAllView();
                            }
                        }
                        break;
                    //Exit menu
                    case '0':
                        break;
                    default:
                        Console.WriteLine("Invalid Selection");
                        break;
                }
            } while (MenuSelection != '0');
        }
        public static void MenuHandler()
        {
            char MenuSelection;
            var student = new Student();

            do
            {
                MenuSelection = StudentMenu.Display();

                switch (MenuSelection)
                {
                    //List all students
                    case '1':
                        var students = new List<Student>();
                        students = StudentManagement.List();
                        StudentView.ListStudentsView(students);
                        break;
                    //List all courses for a student
                    case '2':
                        int studentID = StudentView.InputStudentIDView();
                        student = StudentManagement.GetStudentByID(studentID);
                        StudentView.ListStudentCoursesView(student);
                        break;
                    //Add a student
                    case '3':
                        student = null;
                        student = StudentView.AddStudentView();
                        StudentManagement.AddStudent(student);
                        break;
                    //Enroll a student in a course
                    case '4':
                        var studentCourse = new StudentCourse();
                        studentCourse = EnrollmentView.EnrollStudentView();
                        Enrollment.EnrollStudent(studentCourse);
                        break;
                    //Delete all students
                    case '5':
                        if (StudentView.InputToDeleteAllView() == "y")
                        {
                            if (StudentView.InputAdminPasswordView() == "y")
                            {
                                StudentManagement.DeleteAll();
                                StudentView.DeleteAllView();
                            }
                        }
                        break;
                    //Exit menu
                    case '0':
                        break;
                    default:
                        Console.WriteLine("Invalid Selection");
                        break;
                }
            } while (MenuSelection != '0');
        }