/// <summary> /// Takes in customer name and returns first instance of that customer /// </summary> /// public da.Customer SearchCustomerByName(string query) { //lower cases the query and matches the query to lowercase first names if (repository.GetAll().Any(cust => cust.FirstName.ToLower().Equals(query))) { da.Customer customer = repository.GetAll().First(cust => cust.FirstName.ToLower().Equals(query)); Console.WriteLine($"\nCustomer: {customer.FirstName} {customer.LastName} with CustomerId: {customer.CustomerId}\n"); return(customer); } //if cant find a customer, than display error message...need to implement try catches; else { Console.WriteLine($"\nNo customers exist with this name.\n"); return(null); } }
/// <summary> /// Mohamed Project 0, Grocery store /// </summary> /// <param name="args"></param> public static void Main(string[] args) { //initalize controller repos CustomerController customerController = new CustomerController(); OrderController orderController = new OrderController(); LocationController locationController = new LocationController(); ProductController productController = new ProductController(); //create user from data access model to browse menus da.Customer customer1 = null; //display recurring menu until user presses 7, quit becomes false then bool quit = false; while (!quit) { //display menu returns user input after display options int UserChoice = DisplayMenu(); //switch case to branch into different functionalities switch (UserChoice) { //jump to login function where users can login or create new customer case 1: customer1 = HelperFunctions.Login(customerController); break; case 2: //check to see if user is logged in, then place a new order if (customer1 == null) { Console.WriteLine("Please login."); break; } else { //if program gets here, than place a new order with the controler functions and user as params HelperFunctions.PlaceOrder(customer1, locationController, productController, orderController); } break; case 3: //Search for a customer by id. method called from controller repository for customer //ask for user id Console.WriteLine("------------------------------------------------------------------------------------------\n"); Console.Write("Enter first name to search: "); string query = Console.ReadLine(); string actualQuery = query.ToLower(); //call search for customer method that displays customer details and returns customer customerController.SearchCustomerByName(actualQuery); break; case 4: //Get order details of an order by getting order id Console.WriteLine("------------------------------------------------------------------------------------------\n"); Console.WriteLine("Select Order:\n"); orderController.DisplayOrders(); Console.Write("\nEnter OrderID: "); //obtain order id string selection = Console.ReadLine(); int orderID; //input validation while (!int.TryParse(selection, out orderID)) { Console.WriteLine("Invalid Selection. Please try again."); selection = Console.ReadLine(); } //call display function from ordercontroller to display order details orderController.DisplayOrderDetails(orderID); break; case 5: //Display order history of a store location //obtain the desired locationid Console.WriteLine("\nSelect the location you want the order history for:\n"); locationController.DisplayLocations(); Console.Write("\nEnter the LocationID: "); string cinput = Console.ReadLine(); int locationid; //input validation while (!int.TryParse(cinput, out locationid)) { Console.WriteLine("Invalid Selection. Please try again."); cinput = Console.ReadLine(); } //if locationid is in table, then display order history in that location if (locationController.repository.GetAll().Any(s => s.LocationId == locationid)) { Console.WriteLine($"\nOrder history for {locationController.repository.GetById(locationid).LocationName}"); orderController.DisplayOrderDetailsOfStore(locationid); } //location was not found, display not found message else { Console.WriteLine("\nThis Location does not exist."); } break; case 6: //Display order history for a registered customer //If customer not logged in, prompt user to login if (customer1 == null) { Console.WriteLine("Please login."); } //Find display order history of the customer using order controller repo else { Console.WriteLine($"\nOrder history for customer: {customer1.FirstName} {customer1.LastName}\n"); orderController.DisplayOrderDetailsOfCustomer(customer1.CustomerId); } break; case 7: //if user hits 7, loop breaks and program is ended quit = true; break; } } }