internal void EditRoom() { int roomCount = roomController.RoomCount(); if (roomCount > 0) { Console.WriteLine("Please enter only one room name as displayed below"); DisplayRoom(); Console.Write("> "); var roomNameToChange = Console.ReadLine(); while (roomController.SearchRoom(roomNameToChange) == null) { Console.WriteLine("Sorry! The room you wanna edit does not exist. Try again!"); Console.Write("> "); roomNameToChange = Console.ReadLine(); } Room oldRoom = roomController.SearchRoom(roomNameToChange); Console.Write("You will change old name \"{0}\" to new name or press [Enter] to unchange: ", oldRoom.RoomNo); string updatedName = Console.ReadLine(); if (updatedName == "") { updatedName = oldRoom.RoomNo; } // Keep old name of room to modify if it happens error during updating string name = oldRoom.RoomNo; // Delete course to edit by its id roomController.DeleteRoom(roomNameToChange); if (roomController.UpdateRoom(updatedName)) { Console.WriteLine("You updated new information for room name: " + updatedName); } else { // this condition will run if update name duplicate with other room name roomController.CreateRoom(name); Console.WriteLine("You failed to update new information for room name: " + name); Console.WriteLine(); } } else { Console.WriteLine("Opp! empty room list. You should use selection 1 to add a room."); } Console.WriteLine("Press[Enter] button to continue..."); Console.ReadLine(); }
internal void AddClass() { Console.WriteLine("Add new class"); Course course = null; Lecturer lecturer = null; if (courseController.CourseCount() == 0) { Console.WriteLine("There are no courses yet. You should add some courses firstly."); } else if (lecturerController.LecturerCount() == 0) { Console.WriteLine("There are no lecturers yet. You should add some lecturers firstly."); } else if (roomController.RoomCount() == 0) { Console.WriteLine("There are no rooms yet. You should add some rooms firstly"); } else { Console.WriteLine(); Console.WriteLine("\t\tCourse List\t\t"); cmv.DisplayCourses(); Console.Write("Enter course id: "); string courseId = Console.ReadLine(); while (courseController.SearchCourse(courseId) == null) { Console.Write("This course never exists. Enter course id: "); courseId = Console.ReadLine(); } course = courseController.SearchCourse(courseId); Console.WriteLine(); Console.WriteLine("\t\tLecturer List\t\t"); lmv.DisplayLecturer(); Console.Write("Enter lecturer id: "); string lecturerId = Console.ReadLine(); while (lecturerController.SearchLecturer(lecturerId) == null) { Console.Write("This lecturer never exists. Enter lecturer id: "); lecturerId = Console.ReadLine(); } lecturer = lecturerController.SearchLecturer(lecturerId); ClassPeriod classPeriod = CreateClassPeriod(); if (classController.ClassesCount() > 0) { while (true) { // check whether new class period will clash with others in classes list if (classController.ConflictTime(classPeriod)) { Console.WriteLine("Your chosen class Period has clashed with the others."); Console.WriteLine("Please justify to other class period!"); classPeriod = CreateClassPeriod(); } else if (classController.ConflictLecturer(lecturer.Id, classPeriod)) { Console.WriteLine("Sorry! At your chosen class time, Lecturer has id \"{0}\" will teaching other class", lecturer.Id); Console.WriteLine("Please justify to other class period!"); classPeriod = CreateClassPeriod(); } else { break; } } } if (classController.CreateClass(course, lecturer, classPeriod)) { Console.WriteLine("Congratulation! you added a new class."); } else { Console.WriteLine("Sorry! you failed to add a class."); Console.WriteLine("This class is taken by other lecturer."); } } Console.WriteLine("[Enter] to continue..."); Console.ReadLine(); }