static void Main(string[] args) { using var logStream = new StreamWriter("ef-logs.txt"); var ob = new DbContextOptionsBuilder <Project0Context>(); ob.UseSqlServer(GetConnectionString()); ob.LogTo(logStream.WriteLine, LogLevel.Information); using var context = new Project0Context(ob.Options); IStoreRepository storeRepository = new StoreRepository(context); var prompts = new ConsolePrompts(storeRepository); var interpreter = new ConsoleInputInterpreter(prompts); var user_interface = new StoreInterface(prompts, interpreter); user_interface.Launch(); }
/// <summary> /// Method to show manager menu options and run each option /// </summary> /// <param name="repo">The repo object to use repo methods</param> /// <param name="locations">a list of all the store locations from db</param> public void ShowManagerMenu(StoreRepository repo, List <StoreLocation> locations) { bool runMenu = true; while (runMenu) { //show menu options Console.WriteLine("\nManager Menu:"); Console.WriteLine("1) Search Customer"); Console.WriteLine("2) Display All Orders by Location"); Console.WriteLine("3) Display All Orders by Customer"); Console.WriteLine("4) Display An Orders Details"); Console.Write("Enter a menu number or (q) to quit: "); string input = Console.ReadLine(); switch (input) { case "1": //Customer search Console.Write("\nEnter customers first name: "); string first = Console.ReadLine(); Console.Write("Enter customers last name: "); string last = Console.ReadLine(); Customer cust = repo.GetCustomerByName(first, last); //print customers if (cust == null) { Console.WriteLine("Customer not found in database"); } else { Console.WriteLine("\nID\tFIRST NAME\tLAST NAME\tUSER TYPE"); Console.WriteLine($"{cust.CustomerId}\t{cust.FirstName}\t\t{cust.LastName}\t\t{cust.UserType}"); } break; case "2": //All orders from location //print locations Console.WriteLine("\nLocations to search from: "); foreach (var l in locations) { Console.WriteLine(l.StoreLocationName); } //get location and print out its orders Console.Write("Search Location: "); string locationInput = Console.ReadLine(); foreach (var x in locations) { if (locationInput.Equals(x.StoreLocationName, StringComparison.InvariantCultureIgnoreCase)) { List <Order> orderListLocation = (List <Order>)repo.GetOrdersByLocation(x); Console.WriteLine("\nID\tSTORE ID\tCUSTOMER ID\tDATETIME\t\tTOTAL"); foreach (var o in orderListLocation) { Console.WriteLine($"{o.OrderId}\t{o.OrderStoreLocationId}\t\t{o.OrderCustomerId}\t\t{o.OrderTime}\t${o.OrderTotal}"); } } } break; case "3": //All orders from user //Customer search Console.Write("\nEnter customers first name: "); string firstName = Console.ReadLine(); Console.Write("Enter customers last name: "); string lastName = Console.ReadLine(); Customer c = repo.GetCustomerByName(firstName, lastName); //get customers orders and print List <Order> orderListCustomer = (List <Order>)repo.GetOrdersByCustomer(c); Console.WriteLine("\nID\tSTORE ID\tCUSTOMER ID\tDATETIME\t\tTOTAL"); foreach (var o in orderListCustomer) { Console.WriteLine($"{o.OrderId}\t{o.OrderStoreLocationId}\t\t{o.OrderCustomerId}\t\t{o.OrderTime}\t${o.OrderTotal}"); } break; case "4": //display order items from order number //Get order products Console.Write("\nEnter the order id: "); string orderId = Console.ReadLine(); List <Product> productList = (List <Product>)repo.GetOrderDetails(Int32.Parse(orderId)); //print products if (productList.Count == 0) { Console.WriteLine("Order could not be found."); } else { string header = string.Format("\n{0,-5} {1,-20} {2,-6} {3,-3} {4,-6}", "ID", "NAME", "PRICE", "QTY", "TOTAL"); Console.WriteLine(header); foreach (var p in productList) { string output = string.Format("{0,-5} {1,-20} ${2,-6} {3,-3} ${4,-6}", p.ProductId, p.ProductName, p.ProductPrice, p.ProductQty, p.ProductPrice * p.ProductQty); Console.WriteLine(output); } } break; case "q": runMenu = false; break; default: Console.WriteLine("\nPlease enter a number 1-4 for which menu option you want or (q) to quit."); break; } } }
/// <summary> /// Method to show shopping menus and run their options /// </summary> /// <param name="l">The stores location object</param> /// <param name="c">The users customer object</param> /// <param name="p">List of the stores products from db</param> /// <param name="repo">The repo object to use repo methods</param> public void OpenShopping(StoreLocation l, Customer c, List <Product> p, StoreRepository repo) { bool runShopping = true; List <BusinessLibrary.Product> cart = new List <Product>(); //list off all the products Console.WriteLine($"\n{l.StoreLocationName}'s Products List: "); foreach (var item in p) { Console.WriteLine($"{item.ProductName} ({item.ProductQty}) : ${item.ProductPrice}"); } //get users product choice and add it to cart to purchase while (runShopping) { Console.WriteLine("\nSelect Item to Add to Cart or (q) to quit cart: "); string input = Console.ReadLine(); foreach (var x in p) { if (input.Equals(x.ProductName, StringComparison.InvariantCultureIgnoreCase)) { Console.Write("How many would you like to add to cart (max 5): "); string qtyInput = Console.ReadLine(); if (Int32.Parse(qtyInput) > 5) { Console.WriteLine("Too many to add to cart! Max is 5! Try Again."); } else { Console.WriteLine($"Added {qtyInput} of {x.ProductName} to cart."); Product cartProduct = new Product(x.ProductId, x.ProductName, x.ProductPrice, Int32.Parse(qtyInput)); cart.Add(cartProduct); } } else if (input.Equals("q", StringComparison.InvariantCultureIgnoreCase)) { if (cart.Count() > 0) //cart not empty { Console.WriteLine("\nWould you like to checkout (y/n): "); string checkoutInput = Console.ReadLine(); if (checkoutInput.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { //begin checkout //Display all of products in cart string name = c.FirstName.ToLower(); double total = 0; Console.WriteLine($"\n{char.ToUpper(name[0]) + name.Substring(1)}'s Cart\n--------------------"); foreach (var i in cart) { Console.WriteLine($"{i.ProductName} x {i.ProductQty} : ${i.ProductPrice * i.ProductQty}"); total += i.ProductPrice * i.ProductQty; } Console.WriteLine($"--------------------\nGrand Total: ${total}"); Console.WriteLine("\nWould you like to complete checkout (y/n): "); string completeInput = Console.ReadLine(); if (completeInput.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { int lastid = repo.GetLastOrderId(); //create order and update table values Order o = new Order(lastid + 1, c, DateTime.Now, l, (decimal)total); repo.CreateOrder(o, total); repo.CreateOrderProduct(cart); repo.UpdateProductInventory(l, cart); Console.WriteLine("\nOrder Completed!"); runShopping = false; break; } else { break; } } else { break; } } else //cart empty { runShopping = false; } } } } }