/// <summary> /// input/output for the process of displaying an customer's history with all /// the validation taking place along the way and finally displaying /// the history of the customer meeting the input parameters. /// </summary> public void DisplayCustomerHistory() { CustomerQueries checkCustomer = new CustomerQueries(); OrderCreation checkNum = new OrderCreation(); // get and display all the customer info to pick from var customers = checkCustomer.GetCustomers(); Console.WriteLine("ID\tFirst Name\tLast Name\tUsername"); foreach (var c in customers) { Console.WriteLine($"{c.CustomerID}\t{c.FirstName}" + $"\t\t{c.LastName}\t\t{c.UserName}"); } Console.WriteLine("Please enter an ID from above for the customer you would like to see."); int customerID; do { string input = Console.ReadLine(); if (input == "cancel") { return; } // check if input is an int while (!checkNum.IsValidNum(input)) { Console.WriteLine("Invalid ID number, please enter another."); input = Console.ReadLine(); if (input == "cancel") { return; } } int id = checkNum.StringToInt(input); // check to see if there is a customer with the given ID if (checkCustomer.IsValidCustomerID(id)) { customerID = id; } else { Console.WriteLine("There is no customer with this ID, please enter another."); customerID = 0; } } while (customerID == 0); // repeat if no customer with that ID var customerHistory = checkCustomer.GetCustomerHistory(customerID); var customer = checkCustomer.GetCustomer(customerID); // get and display the order history of that customer if they have one if (customerHistory.Count() == 0) { Console.WriteLine($"As of now, {customer.FirstName} {customer.LastName} has placed no orders."); } else { Console.WriteLine($"Order history for {customer.FirstName} {customer.LastName}"); Console.WriteLine("Location\tOrder ID\tProduct\t\tQuantity\tTotal\t\tTimestamp"); foreach (var o in customerHistory) { double price = o.Product.Price * o.Quantity; Console.WriteLine($"{o.Product.Store.Location}\t{o.OrderID}\t\t" + $"{o.Product.ProductName}\t" + $"{o.Quantity}\t\t${price}\t\t{o.Timestamp}"); } } Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); }