internal void EditCourse() { int courseCount = courseController.CourseCount(); if (courseCount > 0) { Console.WriteLine("Please enter only one course id as displayed below"); DisplayCourses(); Console.Write("> "); var courseIdToChange = Console.ReadLine(); while (courseController.SearchCourse(courseIdToChange) == null) { Console.WriteLine("Sorry! The course you wanna edit does not exist. Try again!"); Console.Write("> "); courseIdToChange = Console.ReadLine(); } Course oldCourse = courseController.SearchCourse(courseIdToChange); Console.Write("You will change old id \"{0}\" to new id or press [Enter] to unchange: ", oldCourse.Id); string updatedId = Console.ReadLine(); Console.Write("You will change old name \"{0}\" to new name or press [Enter] to unchange: ", oldCourse.Name); string updatedName = Console.ReadLine(); Console.Write("You will change old description \"{0}\" to new description or press [Enter] to unchange: ", oldCourse.Description); string updatedDes = Console.ReadLine(); if (updatedId == "") { updatedId = oldCourse.Id; } if (updatedName == "") { updatedName = oldCourse.Name; } if (updatedDes == "") { updatedDes = oldCourse.Description; } // Keep old information of course to modify if it happens error during updating string id = oldCourse.Id; string name = oldCourse.Name; string des = oldCourse.Description; // Delete course to edit by its id courseController.DeleteCourse(courseIdToChange); if (courseController.UpdateCourse(updatedId, updatedName, updatedDes)) { Console.WriteLine("You updated new information for course id: " + updatedId); } else { courseController.CreateCourse(id, name, des); Console.WriteLine(); Console.WriteLine("You failed to update new information for course id: " + id); Console.WriteLine(); } } else { Console.WriteLine("Opp! empty course list. You should use selection 1 to add a course."); } Console.WriteLine("Press[Enter] button to continue..."); Console.ReadLine(); }