/// <summary> /// Creates courses submitted by the user and adds them to the courses in the database. /// Once the user has no more courses to submit, they are returned to the input menu. /// </summary> public static void CourseInput() { Console.WriteLine(); Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); do { Console.WriteLine(); Console.WriteLine("Please type in the title of the course"); string titleinput = StringInput(); Console.WriteLine("Please type in the stream of the course"); string streaminput = StringInput(); Console.WriteLine("Please type in the type of the course"); string typeinput = StringInput(); Console.WriteLine("Please type in the start date of the course (format : dd/mm/yyyy)"); DateTime startDate = DateInput(); Console.WriteLine("Please type in the end date of the course (format : dd/mm/yyyy)"); DateTime endDate = DateInput(); Courses c = new Courses() { title = titleinput, stream = streaminput, type = typeinput, start_date = startDate, end_date = endDate }; using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { db.Courses.Add(c); db.SaveChanges(); } Console.WriteLine(); Console.WriteLine("Great work! A new course has been added to the database."); Console.WriteLine("Do you want to continue adding courses? Type N or n if you want to return to the previous menu or any other button to continue adding"); } while (!ExitCheck()); InputMenu(); }
/// <summary> /// Creates assignments submitted by the user and adds them to the assignments in the database. /// Once the user has no more assignments to submit, they are returned to the input menu. /// </summary> public static void AssignmentInput() { Console.WriteLine(); Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); do { Console.WriteLine(); Console.WriteLine("Please type in the title of the assignment"); string titleinput = StringInput(); Console.WriteLine("Please type in the description of the assignment"); string descriptioninput = StringInput(); Console.WriteLine("Please type in the submission date of the assignment(format : dd/mm/yyyy)"); DateTime subDate = DateInput(); Console.WriteLine("Please type in the oral mark of the assignment"); int oralmark = IntegerInput(); Console.WriteLine("Please type in the total mark of the assignment"); int totalmark = IntegerInput(); int correspondingCourse = CourseMatch(); Assignments a = new Assignments() { title = titleinput, description = descriptioninput, subDateTime = subDate, oralMark = oralmark, totalMark = totalmark, courseId = correspondingCourse }; using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { db.Assignments.Add(a); db.SaveChanges(); } Console.WriteLine(); Console.WriteLine("Great work! A new assignment has been added to the database."); Console.WriteLine("Do you want to continue adding assignments? Type N or n if you want to return to the previous menu or any other button to continue adding"); } while (!ExitCheck()); InputMenu(); }
/// <summary> /// Prints all courses in the database /// </summary> public static void PrintAllCourses() { Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { foreach (var item in db.Courses) { Console.WriteLine(item.courseId + " " + item.title + " " + item.stream + " " + item.type + " " + item.start_date + " " + item.end_date); } } Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); }
/// <summary> /// Prints all assignments in the database /// </summary> public static void PrintAllAssignments() { Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { foreach (var item in db.Assignments) { Console.WriteLine(item.title + " " + item.description + " " + item.subDateTime + " " + item.oralMark + " " + item.totalMark); } } Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); }
/// <summary> /// Prints all trainers in the database /// </summary> public static void PrintAllTrainers() { Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { foreach (var item in db.Trainers) { Console.WriteLine(item.firstName + " " + item.lastName + " " + item.subject); } } Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); }
/// <summary> /// Prints all students in the database /// </summary> public static void PrintAllStudents() { Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { foreach (var item in db.Students) { Console.WriteLine(item.firstName + " " + item.lastName + " " + item.dateOfBirth + " " + item.tuitionFees); } } Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); }
/// <summary> /// Prints all assignments per course in the database /// </summary> public static void PrintAllAssignmentsPerCourse() { Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { foreach (var item in db.Courses) { Console.WriteLine(item.title + " " + item.stream + " " + item.type); foreach (var a in item.Assignments) { Console.Write("\t"); Console.WriteLine(a.title + " " + a.description); } } } Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); }
/// <summary> /// Prints all trainers per course in the database /// </summary> public static void PrintAllTrainersPerCourse() { Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { foreach (var item in db.Courses) { Console.WriteLine(item.title + " " + item.stream + " " + item.type); foreach (var t in item.Trainers) { Console.Write("\t"); Console.WriteLine(t.firstName + " " + t.lastName); } } } Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); }
/// <summary> /// Overloaded function. Prints the available courses and checks which courses the user wants to assign to. Used for the many-to-many relationships /// </summary> /// <param name="items">The list of the previous values the user has typed in to check against their current input</param> public static void CourseMatch(List <int> items) { int range = 0; using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { range = db.Courses.Count(); } do { PrintAllCourses(); Console.WriteLine("Please type in the number that corresponds to the respective course. Any numbers above or below that range will not be accepted."); int input = IntegerInput(); CheckExistsAndAdd(items, input, range); Console.WriteLine("Would you like to stop adding courses? Type N or n if you want to stop or any other character to continue"); } while (!ExitCheck()); }
/// <summary> /// Creates students submitted by the user and adds them to the students in the database. /// Once the user has no more students to submit, they are returned to the input menu. /// </summary> public static void StudentInput() { Console.WriteLine(); Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); do { Console.WriteLine(); Console.WriteLine("Please type in the first name of the student"); string firstname = StringInput(); Console.WriteLine("Please type in the last name of the student"); string lastname = StringInput(); Console.WriteLine("Please type in the student's date of birth (format : dd/mm/yyyy)"); DateTime dateofbirth = DateInput(); Console.WriteLine("Please type in the student's tuition fees"); int tuitionfees = IntegerInput(); List <int> courses = new List <int>(); Console.WriteLine("Does this student attend any courses? If yes, type any character to start adding courses. If no, type n or N"); if (!ExitCheck()) { CourseMatch(courses); } Students s = new Students() { firstName = firstname, lastName = lastname, dateOfBirth = dateofbirth, tuitionFees = tuitionfees }; using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { for (int i = 0; i < courses.Count; i++) { int currentcourse = courses[i]; foreach (var item in db.Courses.Where(x => x.courseId == currentcourse)) { s.Courses.Add(item); } } db.Students.Add(s); db.SaveChanges(); } Console.WriteLine(); Console.WriteLine("Great work! A new student has been added to the database."); Console.WriteLine("Do you want to continue adding students? Type N or n if you want to return to the previous menu or any other button to continue adding"); } while (!ExitCheck()); InputMenu(); }
/// <summary> /// Creates trainers submitted by the user and adds them to the trainers in the database. /// Once the user has no more trainers to submit, they are returned to the input menu. /// </summary> public static void TrainerInput() { Console.WriteLine(); Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); do { Console.WriteLine(); Console.WriteLine("Please type in the first name of the trainer"); string firstname = StringInput(); Console.WriteLine("Please type in the last name of the trainer"); string lastname = StringInput(); Console.WriteLine("Please type in the subject of the trainer"); string subj = StringInput(); List <int> courses = new List <int>(); Console.WriteLine("Does this trainer teach any courses? If yes, type any character to start adding courses. If no, type n or N"); if (!ExitCheck()) { CourseMatch(courses); } Trainers t = new Trainers() { firstName = firstname, lastName = lastname, subject = subj }; using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { for (int i = 0; i < courses.Count; i++) { int currentcourse = courses[i]; foreach (var item in db.Courses.Where(x => x.courseId == currentcourse)) { t.Courses.Add(item); } } db.Trainers.Add(t); db.SaveChanges(); } Console.WriteLine(); Console.WriteLine("Great work! A new trainer has been added to the database."); Console.WriteLine("Do you want to continue adding trainers? Type N or n if you want to return to the previous menu or any other button to continue adding"); } while (!ExitCheck()); InputMenu(); }
/// <summary> /// Prints all students that attend multiple courses in the database /// </summary> public static void PrintAllStudentsInMultipleCourses() { Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { foreach (var item in db.Students) { if (item.Courses.Count > 1) { Console.WriteLine(item.firstName + " " + item.lastName + " participates in " + item.Courses.Count + " Courses"); foreach (var c in item.Courses) { Console.Write("\t"); Console.WriteLine(c.title + " " + c.stream + " " + c.type); } } } } Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); }
/// <summary> /// Overloaded function. Prints the available courses and checks which course the user wants to assign to. Used for the one-to-many relationships /// </summary> /// <returns>The courseId of the course the user wants to assign to</returns> public static int CourseMatch() { int range = 0; int input = 0; bool Matched = false; using (PerikleousBootcampEntities db = new PerikleousBootcampEntities()) { range = db.Courses.Count(); } do { PrintAllCourses(); Console.WriteLine("Please type in the number of the course you want to assign to. An assignment can be assigned to only one course."); Console.WriteLine("Any numbers above or below that range will not be accepted."); input = IntegerInput(); Matched = CheckRange(input, range); } while (!Matched); return(input); }