// Method to remove customer from the crm file public void RemoveCustomerSubmenu(bool clear = true) { if (clear) { Console.Clear(); } Console.WriteLine("### Delete Customer Submenu ###\n"); DeleteCRMValidationInput(); // Ensure that the desired ID to be deleted exists in the customer list to execute deletion if (Crm.CustomerList.Any(customer => customer.ID == DeleteRecordID)) { // deletion is successful if customer is not renting a vehicle if (Crm.RemoveCustomer(DeleteRecordID, Fleet)) { Crm.SaveToFile(); Console.WriteLine($"\nSuccessfully deleted the Customer with an ID of '{DeleteRecordID}'"); } else { Console.WriteLine($"\nDeletion Unsuccessful. Customer '{DeleteRecordID}' is currently renting a vehicle."); } LastMRRCscreen(() => SubMenu("Customer"), () => RemoveCustomerSubmenu()); } // If the desired ID to be deleted is not in the list, prompt a message else { Console.Clear(); Console.WriteLine("Customer with an ID of '{0}' does not exist in the Customers List\n", DeleteRecordID); RemoveCustomerSubmenu(false); LastMRRCscreen(() => SubMenu("Customer"), () => RemoveCustomerSubmenu()); } }
// Main method interface to do modify operations on vehicle public void ModifyVehicleSubmenu(bool clear = true) { if (clear) { Console.Clear(); } Console.WriteLine("### Modify Vehicle Submenu ###\n"); // Require the operator to enter the vehicle registration to be modified ModifyRegoValidInput(); // Save the changed ID to -1 in case customer decideds to retain the same ID in the modification menu. Crm.SaveToFile(); string subMenu = "a) Modify Default Vehicle Fields" + "\nb) Modify All Vehicle Fields"; Console.WriteLine("\nPlease enter a character from the options below:\n"); Console.WriteLine(subMenu); // Return the vehicle which matches the provided registration to modify and assign to vehicle object Vehicle vehicle = Fleet.GetVehicle(regoToModify); // Wait for user to input the next key inputkey = Console.ReadKey(); switch (inputkey.Key) { case A_Pressed: ModifyVehicle(vehicle); break; case B_Pressed: ModifyVehicle(vehicle, true); break; case H_Pressed: MRRCInterface(); break; case Backspace_Pressed: ModifyVehicleSubmenu(); break; case Escape_Pressed: QuitMessage(); break; case Q_Pressed: SubMenu("Fleet"); break; default: // if any key other than above listed is pressed, do: Console.Clear(); Console.WriteLine("You Pressed '{0}', Please enter a valid option\n", inputkey.Key.ToString()); ModifyVehicleSubmenu(false); break; } }
// Method to modify a specific customer which exists in the crm file public void ModifyCustomerSubmenu(bool clear = true) { if (clear) { Console.Clear(); } Console.WriteLine("### Modify Customer Submenu ###\n"); ModifyCRMValidationInput(); // Return the customer which matches the provided ID to modify and assign to modifiedcustomer object Customer customer = Crm.GetCustomer(IDtoMofify); // if the returned customer in the modified customer object is not null, proceed to modify if (customer != null) { // Store old customers ID, title, first and last names into variables int OldID = customer.ID; string OldTitle = customer.title, OldFirstName = customer.firstName, OldLastName = customer.lastName; // Set the customer ID to the highest id value + 1, in case the customer wants to retain his/her ID and only wants // to modify the fields. We set the ID to this so that the validation doesnt prompt an error that the ID wanting // to be retained already exists. If the ID is retained, there is still unique ID's in the list int HighestID = Crm.CustomerList.Max(Customer => Customer.ID) + 1; customer.ID = HighestID; // Save the changed ID value in case customer decideds to retain the same ID in the modification menu. Crm.SaveToFile(); ModifyIDValidationInput(); customer.ID = IDtoMofify; Console.Write("Title*: "); title = StringToTitleCase(Console.ReadLine()); customer.title = title; Console.Write("FirstName*: "); firstName = StringToTitleCase(Console.ReadLine()); customer.firstName = firstName; Console.Write("LastName*: "); lastName = StringToTitleCase(Console.ReadLine()); customer.lastName = lastName; GenderValidationInput(); customer.gender = Gender; DOBValidationInput(); customer.DOB = DOB; Console.Write("\nSuccessfully modified customer '{0} - {1} {2} {3}' to '{4} {5} {6} {7}' within the customers list", OldID, OldTitle, OldFirstName, OldLastName, IDtoMofify, title, firstName, lastName); Crm.SaveToFile(); LastMRRCscreen(() => SubMenu("Customer"), () => ModifyCustomerSubmenu()); } // If the returned customer in the object is null, then the customer does not exist else { Console.Clear(); Console.WriteLine("Customer with an ID of '{0}' does not exist in the Customers List\n", IDtoMofify); ModifyCustomerSubmenu(false); LastMRRCscreen(() => SubMenu("Customer"), () => ModifyCustomerSubmenu()); } }
// Method which holds the interface for adding a customer to the crm file public void NewCustomerSubmenu(bool clear = true) { if (clear) { Console.Clear(); } Console.WriteLine("### New Customer Submenu ###\n"); Console.WriteLine("Please fill the following fields (fields with * are required)\n"); Console.Write("Title*: "); title = StringToTitleCase(Console.ReadLine()); Console.Write("FirstName*: "); firstName = StringToTitleCase(Console.ReadLine()); Console.Write("LastName*: "); lastName = StringToTitleCase(Console.ReadLine()); GenderValidationInput(); DOBValidationInput(); // Determine the highest ID number in the list int HighestID; // if the list has any customer, we determine the max ID using the max method on the list of objects if (Crm.CustomerList.Count() > 0) { HighestID = Crm.CustomerList.Max(Customer => Customer.ID); }// If the list has no customers, we make the id to be -1, so when the first customer is added, it will // increment by one, which will be 0 (-1 + 1 = 0). else { HighestID = -1; } // The customer id number must be unqiue, so we will make it equal to the highest ID number in the crm list and // increment it by one int CustomerIDNumber = HighestID + 1; // Add new customer Customer newCustomer = new Customer(CustomerIDNumber, title, firstName, lastName, Gender, DOB); if (Crm.AddCustomer(newCustomer)) { Console.Write("\nSuccessfully created new customer '{0} - {1} {2} {3}' and added to customer list", CustomerIDNumber, title, firstName, lastName); Crm.SaveToFile(); } // If user presses any key, prompt the end of the menu LastMRRCscreen(() => SubMenu("Customer"), () => NewCustomerSubmenu()); }