public void DeleteExistingCustomer() { try { var customer = new GetAllCustomers(); customer.GetAllCustomersInfo(); Console.WriteLine("Choose Customer to delete by entering Customer Id: "); var userinput = Convert.ToInt32(Console.ReadLine()); var getCustomer = new ReturnCustomer(); var customerToDelete = getCustomer.Return_Customer(userinput); if (customerToDelete == null) { Console.WriteLine("No customer was found.."); Visuals.ReturnToMainMenu(); } _bicycleRentalDbContext .Customers .Remove(customerToDelete); _bicycleRentalDbContext .SaveChanges(); Console.WriteLine($"Existing customer with customer id: {customerToDelete.Customer_id} deleted successfully!"); } catch (Exception ex) { Console.WriteLine($"You messed up! {ex}"); } }
/// <summary> /// Get specific customer info /// </summary> public void GetSpecificCustomerInfo() { try { var customers = new GetAllCustomers(); Console.WriteLine($"Here are all existing customers:\n"); customers.GetAllCustomersInfo(); Console.WriteLine($"\nChoose specific customer to view by entering customer Id "); var userInput = Convert.ToInt32(Console.ReadLine()); var customer = _bicycleRentalDbContext.Customers.Find(userInput); if (customer == null) { Console.WriteLine("No customer was found.."); Visuals.ReturnToMainMenu(); } Console.Clear(); Console.WriteLine($"Your specific customer: "); Console.WriteLine($"Customer_id: {customer.Customer_id}"); Console.WriteLine($"Customer_First_Name: {customer.Customer_First_Name}"); Console.WriteLine($"Customer_Last_Name: {customer.Customer_Last_Name}"); Console.WriteLine($"Gender: {customer.Gender}"); Console.WriteLine($"Phone_number: {customer.Phone_number}"); Console.WriteLine($"E_mail: {customer.E_mail}"); } catch (Exception ex) { Console.WriteLine($"You messed up! {ex}"); } }
public void UpdateExistingCustomer() { try { var customer = new GetAllCustomers(); customer.GetAllCustomersInfo(); Console.WriteLine("Choose Customer to update by entering Customer Id: "); var userinput = Convert.ToInt32(Console.ReadLine()); var getCustomer = new ReturnCustomer(); var customerToUpdate = getCustomer.Return_Customer(userinput); if (customerToUpdate == null) { Console.WriteLine("No customer was found.."); Visuals.ReturnToMainMenu(); } Console.WriteLine("Change Customer information"); Console.WriteLine(""); Console.WriteLine("Update Customer_First_Name"); customerToUpdate.Customer_First_Name = Console.ReadLine(); Console.WriteLine("Update Customer_Last_Name"); customerToUpdate.Customer_Last_Name = Console.ReadLine(); Console.WriteLine("Update Gender"); customerToUpdate.Gender = Console.ReadLine(); Console.WriteLine("Phone_number"); customerToUpdate.Phone_number = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Update E_mail"); customerToUpdate.E_mail = Console.ReadLine(); _bicycleRentalDbContext .Customers .Update(customerToUpdate); _bicycleRentalDbContext .SaveChanges(); Console.WriteLine("Existing Customer updated successfully!"); Console.WriteLine(""); Console.WriteLine("---------------------------------------"); Console.WriteLine($"Customer Customer_First_Name: {customerToUpdate.Customer_First_Name}"); Console.WriteLine($"Customer Customer_Last_Name: {customerToUpdate.Customer_Last_Name}"); Console.WriteLine($"Customer Gender: {customerToUpdate.Gender}"); Console.WriteLine($"Customer Phone_number: {customerToUpdate.Phone_number}"); Console.WriteLine($"Customer E_mail: {customerToUpdate.E_mail}"); Console.WriteLine("---------------------------------------"); } catch (Exception ex) { Console.WriteLine($"You messed up! {ex}"); } }
/// <summary> /// Choose this to enter the Show All Information menu /// </summary> public static void ShowAllInformation() { var bicycles = new GetAllBicycles(); var customers = new GetAllCustomers(); var bicycleBrands = new GetAllBicycleBrands(); var filteredCustomer = new GetFilteredCustomers(); Console.Clear(); Console.WriteLine("1: Show all Bicycles"); Console.WriteLine("2: Show all Customers"); Console.WriteLine("3: Show all Bicycle Brands"); Console.WriteLine("4: Show all Customers who's first name starts with the letter 'A'"); Console.WriteLine(""); var userChoice = Console.ReadLine(); switch (userChoice) { case "1": bicycles.GetAllBicyclesInfo(); ReturnToMainMenu(); break; case "2": customers.GetAllCustomersInfo(); ReturnToMainMenu(); break; case "3": bicycleBrands.GetAllBicycleBrandsInfo(); ReturnToMainMenu(); break; case "4": filteredCustomer.GetFilteredCustomersInfo(); ReturnToMainMenu(); break; default: Console.Clear(); Console.WriteLine("Input does not exist!.. Press any key except the one you pressed to get here!.. try again!.. "); Console.ReadKey(); ShowAllInformation(); break; } }
/// <summary> /// Gets you the customer with booked bicycle /// </summary> public void GetCustomerWithBookingAndBicycle() { try { var customer = new GetAllCustomers(); customer.GetAllCustomersInfo(); Console.WriteLine("Choose Customer With Bicycle to show by entering Customer Id: "); var customerId = Convert.ToInt32(Console.ReadLine()); var getCustomerWithBookingWithBicycle = _bicycleRentalDbContext.Customers .Include(g => g.Booking_details) .ThenInclude(b => b.Bicycle) .ThenInclude(b => b.Bicycle_brand) .FirstOrDefault(g => g.Customer_id == customerId); Console.Clear(); Console.WriteLine("Here is your customer with booking and bicycle:"); Console.WriteLine("------------------------------------------"); Console.WriteLine($"Customer First Name: {getCustomerWithBookingWithBicycle.Customer_First_Name}"); Console.WriteLine($"Customer Last Name: {getCustomerWithBookingWithBicycle.Customer_Last_Name}"); Console.WriteLine($"Customer Gender: {getCustomerWithBookingWithBicycle.Gender}"); Console.WriteLine($"Customer Phone number: {getCustomerWithBookingWithBicycle.Phone_number}"); Console.WriteLine($"Customer E_mail: {getCustomerWithBookingWithBicycle.E_mail}"); Console.WriteLine("------------------------------------------"); foreach (var item in getCustomerWithBookingWithBicycle.Booking_details) { Console.WriteLine($"Booking_date: {item.Booking_date}"); Console.WriteLine($"Bicycle_type: {item.Bicycle.Bicycle_brand.Bicycle_type}"); Console.WriteLine($"Bicycle_name: {item.Bicycle.Bicycle_brand.Bicycle_name}"); Console.WriteLine($"Return_due_date: {item.Return_due_date}"); Console.WriteLine("----------------------------------------"); } } catch (Exception ex) { Console.WriteLine($"You messed up! {ex}"); } }