public static Course AddCourseView() { string courseName = ""; var course = new Course(); Console.Clear(); Console.WriteLine("ADD A COURSE"); Console.WriteLine("------------"); Console.WriteLine("\n"); Console.Write("Name: "); courseName = Console.ReadLine(); if (courseName != "") { course.Name = courseName; return course; } else { Console.WriteLine("Name is a required field.\n"); Console.Write("\nPress [Enter] key to continue... "); Console.ReadLine(); return null; } }
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 AddCourse(Course course) { using (var context = new EFCoreRefContext()) { if (course != null) { context.Course.Add(course); context.SaveChanges(); } } }
public static void ListStudentsEnrolledInCourse(Course course) { Console.Clear(); Console.WriteLine("LIST STUDENTS ENROLLED IN COURSE"); Console.WriteLine("--------------------------------"); Console.WriteLine("\n"); if (course != null) { Console.WriteLine("The following students are enrolled in {0}:\n", course.Name); Console.WriteLine("\tStudent ID\tStudent Name"); foreach (var student in course.StudentCourses) { Console.WriteLine("\t{0}\t\t{1}", student.Student.ID, student.Student.Name); } } else { Console.WriteLine("Course is not in the database"); } Console.Write("\nPress [Enter] key to continue... "); Console.ReadLine(); }