static Customer LogIn(IProject0Repository projectRepository) { var customer = new Customer(); var customerList = projectRepository.GetCustomers(); while (customer.FirstName == null) { _io.Output("Enter your firstName: "); string firstName = _io.Input(); _io.Output("Enter your lastName: "); string lastName = _io.Input(); try { var test = customerList.First(c => c.FirstName.ToLower() == firstName && c.LastName.ToLower() == lastName); customer = test; } catch (ArgumentException ex) { _io.Output("Your name does not match our database."); s_logger.Info(ex); Console.WriteLine(ex.Message); } } return(customer); }
/// <summary> /// Write a list of customers to console with optional search-by-name. /// </summary> public static void DisplayCustomers(IProject0Repository repository) { Console.Write(" Enter a customer name to search for? (Y/N) : "); string doSearch = Console.ReadLine().ToLower(); string search = null; if (doSearch == "y" || doSearch == "yes") { Console.Write(" "); search = Console.ReadLine(); } Console.WriteLine(); IEnumerable <ICustomer> result = repository.GetCustomers(search); foreach (ICustomer c in result) { Console.WriteLine(c.FirstName + " " + c.LastName + " ; " + c.Address + ", " + c.City + " " + c.State + ", " + c.Country + " " + c.PostalCode + " ; " + c.Phone + " ; " + c.Email); } Console.WriteLine(); Console.Write(" Press Enter to continue"); Console.ReadLine(); Console.WriteLine(); }
static void DisplayCustomerHistory(IProject0Repository projectRepository) { _io.Output("Select an Customer: \n"); var customers = projectRepository.GetCustomers(); var customerList = customers.ToList <Customer>(); int customerId = 0; while (customerId == 0) { foreach (var item in customerList) { _io.Output($"{item.FirstName} {item.LastName} \n"); } string[] customerInput = _io.Input().Split(' '); try { customerId = customers.First(c => c.FirstName.ToLower() == customerInput[0] && c.LastName.ToLower() == customerInput[1]).Id; } catch (ArgumentException ex) { _io.Output("Name Invalid. It does not match any in our database."); s_logger.Info(ex); Console.WriteLine(ex.Message); } } var orderHistory = projectRepository.GetOrders().Where(o => o.CustomerId == customerId).ToList(); foreach (var item in orderHistory) { var productName = projectRepository.GetProductById(item.ProductId).Name; var customerName = projectRepository.GetCustomerById(item.CustomerId).FirstName + " " + projectRepository.GetCustomerById(item.CustomerId).LastName; //var locationName = projectRepository.GetLocationsById(item.CustomerId).LocationName; //_io.Output($"ID: {item.Id} Product Name: {productName} Quantity: {item.Quantity} " + // $"Location: {locationName} Customer Name: {customerName} \n"); _io.Output($"ID: {item.Id} Product Name: {productName} Quantity: {item.Quantity} " + $" Customer Name: {customerName} \n"); } }