public static void DisplayOrder(Library.Order order, List <Library.OrderItem> orderItems, List <Library.Cupcake> cupcakes) { decimal sum = 0; int incrementer = 1; Console.WriteLine($"Order Id: {order.Id}, Location Id: {order.OrderLocation}, " + $"Customer Id, {order.OrderCustomer}, Order Time: {order.OrderTime},"); foreach (var orderItem in orderItems) { Console.WriteLine($"\tOrder Item {incrementer}: " + $"{cupcakes.Single(c => c.Id == orderItem.CupcakeId).Type}, \n" + $"\tQnty {incrementer}: {orderItem.Quantity}"); incrementer++; sum += orderItem.Quantity * cupcakes.Single(c => c.Id == orderItem.CupcakeId).Cost; } Console.WriteLine($"Order Id {order.Id} total cost: ${sum}"); Console.WriteLine(); }
public ActionResult AddOrder(IFormCollection collection) { try { int stoID = Convert.ToInt32(TempData["StoID"]); int custID = Convert.ToInt32(TempData["CustID"]); lib.Store sto = irepOrigSto.GetStores(stoID).First(); lib.Customer cust = irepOrigCust.GetCustomers(cusid: custID).First(); lib.Order ord = new lib.Order(cust, sto, 0); irepOrig.Order(ord); irepOrig.EndMe(); ord = irepOrig.GetOrdersByCust(custID).Last(); foreach (var item in collection) { foreach (var iven in sto.iven) { if (iven.Key.MerchID == Convert.ToInt32(item.Key)) { var a = irepOrigMerch.GetMerch(iven.Key.MerchID).First(); ord.details.Add(a, Convert.ToInt32(item.Value)); break; } } } foreach (var item in ord.details) { sto.ChangeStock(item.Key, -1 * item.Value); } irepOrig.AddOrder(ord); TempData.Keep(); irepOrigSto.UpdateStore(sto); irepOrigSto.help(); irepOrig.EndMe(); return(RedirectToAction(nameof(EndOrder))); } catch { return(View()); } }
// GET: Order/Delete/5 public ActionResult EndOrder() { decimal btotal = 0; int custID = Convert.ToInt32(TempData["CustID"]); lib.Order ord = irepOrig.GetOrdersByCust(custID).Last(); foreach (var item in ord.details) { btotal += item.Key.MerchPrice * item.Value; } var viewMod = ord.details.Select(i => new Models.EndOrderViewMod { merchID = i.Key.MerchID, merchName = i.Key.MerchName, merchPrice = i.Key.MerchPrice, quantity = i.Value, total = i.Key.MerchPrice * i.Value }); ViewData["BigTotal"] = btotal; return(View(viewMod)); }
public static void Run(Project0Context dbContext) { //establish contexts with domains var CusCon = new ef.CustomerRep(dbContext); var MerCon = new ef.MerchRep(dbContext); var StoCon = new ef.StoreRep(dbContext); var OrdCon = new ef.OrderRep(dbContext); while (true) { Console.Clear(); Console.WriteLine("Manager\n"); Console.WriteLine(); Console.WriteLine("1:\tAdd a body"); Console.WriteLine("2:\tStart a Search"); Console.WriteLine("3:\tWant to Order Something?"); Console.WriteLine("4:\tFare Thee Well"); Console.WriteLine(); Console.WriteLine("What do you want to do?"); var input = Console.ReadLine(); if (input == "1") { string fname = null; string lname = null; Console.Clear(); Console.WriteLine("Adding a Customer\n"); while (fname == null) { Console.Write("Enter First name: "); fname = Console.ReadLine(); if (fname == "") { fname = null; } } while (lname == null) { Console.Write("Enter Last name: "); lname = Console.ReadLine(); if (lname == "") { lname = null; } } Console.WriteLine($"\nCreating a new Customer with \nFirst Name: {fname}\nLast Name: {lname}"); try { var newCus = new lib.Customer(fname, lname); CusCon.AddCust(newCus); CusCon.why(); var dbCusId = CusCon.GetCustomers(fname, lname).Last().CustomerID; Console.WriteLine($"Customer has been added.\nID: {dbCusId}"); Console.WriteLine("Press a key to keep going"); Console.ReadKey(); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } else if (input == "2") { while (true) { Console.Clear(); Console.WriteLine("Search for something Screen"); Console.WriteLine("1:\tSearch for Customer"); Console.WriteLine("2:\tSearch for Store"); Console.WriteLine("3:\tSearch for Orders for Customer"); Console.WriteLine("4:\tSearch for Orders for Store"); Console.WriteLine("5:\tSearch for Order Details"); Console.WriteLine("6:\tLet Me Out"); Console.WriteLine(); Console.WriteLine("What do you want to do?"); var input2 = Console.ReadLine(); if (input2 == "1") { string fnamesearch = null; string lnamesearch = null; Console.Clear(); Console.WriteLine("Searching for Customers\n"); Console.WriteLine("Give me a First Name to search for "); Console.WriteLine("\tor you could give me no name: "); fnamesearch = Console.ReadLine(); if (fnamesearch == null) { fnamesearch = null; } Console.WriteLine("Now give me a Last Name to search for "); Console.WriteLine("\tor you can leave nothing here also: "); lnamesearch = Console.ReadLine(); if (lnamesearch == null) { lnamesearch = null; } Console.WriteLine($"So, I am searching for {fnamesearch} {lnamesearch} right? Give me a second."); Console.WriteLine(); var cusSearch = CusCon.GetCustomers(fnamesearch, lnamesearch).ToList(); foreach (lib.Customer item in cusSearch) { Console.WriteLine(item.ToString() + "\n"); } Console.WriteLine("\nPress something to continue"); Console.ReadKey(); } else if (input2 == "2") { Console.Clear(); Console.WriteLine("Store: \n"); var sto = StoCon.GetStores().ToList(); foreach (lib.Store item in sto) { Console.WriteLine(item.ToString() + "\n"); } Console.WriteLine("\nPunch a key to keep moving"); Console.ReadKey(); } else if (input2 == "3") { string input2key; int custId = 0; bool isInt = false; do { Console.Clear(); Console.WriteLine("Display All Orders for a Customer\n"); Console.Write("Enter a Customer ID: "); input2key = Console.ReadLine(); isInt = Int32.TryParse(input2key, out custId); }while (!isInt); var results = OrdCon.GetOrdersByCust(id: custId).ToList(); if (results.Count > 0) { foreach (lib.Order ord in results) { Console.WriteLine(ord.ToString() + "\n"); } } else { Console.WriteLine($"No results matching CustomerID {custId}"); } Console.WriteLine("Press any key to continue."); Console.ReadKey(); } else if (input2 == "4") { string input2key; int stoId = 0; bool isInt = false; do { Console.Clear(); Console.WriteLine("Display All Orders for a Location\n"); Console.Write("Enter a Location ID: "); input2key = Console.ReadLine(); isInt = Int32.TryParse(input2key, out stoId); }while (!isInt); var results = OrdCon.GetOrdersByStore(stoId).ToList(); if (results.Count > 0) { foreach (lib.Order ord in results) { Console.WriteLine(ord.ToString() + "\n"); } } else { Console.WriteLine($"No results matching LocationID {stoId}"); } Console.WriteLine("Press any key to continue."); Console.ReadKey(); } else if (input2 == "5") { string input2key; int ordId = 0; bool isInt = false; do { Console.Clear(); Console.WriteLine("Display Details of an Order:\n"); Console.Write("Enter a Order ID: "); input2key = Console.ReadLine(); isInt = Int32.TryParse(input2key, out ordId); }while (!isInt); var result = OrdCon.GetOrdersByID(ordId).ToList().FirstOrDefault(); if (result == null) { Console.WriteLine($"No results matching OrderID {ordId}"); } else { Console.WriteLine(result.ToString()); Console.WriteLine(result.OrderToString()); } Console.WriteLine("Press any key to continue."); Console.ReadKey(); } else if (input2 == "6") { break; } } } else if (input == "3") { string inputStr; int custId = 0; int stoId = 0; bool isInt = false; do { Console.Clear(); Console.WriteLine("Place an Order Menu\n"); Console.Write("Enter a Customer ID: "); inputStr = Console.ReadLine(); isInt = Int32.TryParse(inputStr, out custId); }while (!isInt); var cust = CusCon.GetCustomers(cusid: custId).FirstOrDefault(); if (cust == null) { Console.WriteLine($"Customer {custId} does not exist."); break; } else { Console.WriteLine("Customer found:\n"); Console.WriteLine(cust.ToString()); } isInt = false; do { Console.Clear(); Console.WriteLine("Place an Order Menu\n"); Console.WriteLine($"Enter a Customer ID: {custId}"); Console.WriteLine("Customer found:\n"); Console.WriteLine(cust.ToString()); Console.Write("Enter a Location ID: "); inputStr = Console.ReadLine(); isInt = Int32.TryParse(inputStr, out stoId); }while (!isInt); var loc = StoCon.GetStores(stoId).FirstOrDefault(); if (loc == null) { Console.WriteLine($"Store {stoId} does not exist."); break; } else { Console.WriteLine("Store found:\n"); Console.WriteLine(loc.ToString()); } bool abort = false; do { Console.Write("Would you like to continue? (YES/NO): "); string answer = Console.ReadLine(); if (answer.ToUpper() == "YES") { break; } else if (answer.ToUpper() == "NO") { abort = true; } }while (!abort); if (!abort) { try { var ord = new lib.Order(cust, loc, 0); OrdCon.Order(ord); OrdCon.EndMe(); ord = OrdCon.GetOrdersByCust(cust.CustomerID).Last(); int prodId = 0; bool done = false; do { do { prodId = 0; Console.Clear(); Console.WriteLine("Place an Order Menu\n"); Console.WriteLine($"Customer:\n{cust.ToString()}"); Console.WriteLine($"Store:\n{loc.ToString()}"); Console.WriteLine(); Console.WriteLine("Store inventory:"); Console.WriteLine(loc.InventoryToString()); Console.WriteLine(); Console.WriteLine("Your basket:"); Console.WriteLine(ord.OrderToString()); Console.Write("Enter a Product Id, or DONE if finished: "); inputStr = Console.ReadLine(); if (inputStr.ToUpper() == "DONE") { done = true; isInt = true; } else { isInt = Int32.TryParse(inputStr, out prodId); } }while (!isInt); if (!done) { var prod = MerCon.GetMerch().FirstOrDefault(); if (prod == null) { Console.WriteLine($"Merch {prodId} does not exist"); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } /*else if (!loc.FindItemById(prodId)) * { * Console.WriteLine($"Merch {prodId} is not in this location's inventory"); * Console.WriteLine("\nPress any key to continue."); * Console.ReadKey(); * }*/ else { bool isIntQuantity = false; int quantity = 0; do { Console.Write("Enter a quanity: "); inputStr = Console.ReadLine(); isIntQuantity = Int32.TryParse(inputStr, out quantity); }while (!isIntQuantity); if (loc.ChangeStock(prod, -1 * quantity)) { //ord.details.Add(prod, quantity); Console.WriteLine($"Added {quantity} {prod.MerchName}s to Order."); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } } } }while (!done); OrdCon.AddOrder(ord); OrdCon.EndMe(); Console.Clear(); Console.WriteLine($"Order Complete.\n"); Console.WriteLine(ord.ToString()); Console.WriteLine(ord.OrderToString()); } catch (ArgumentNullException ex) { Console.WriteLine(ex.Message); } } Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } else if (input == "4") { Console.WriteLine("Alright, See you next time"); Console.WriteLine("\n Press any key to leave"); Console.ReadKey(); break; } } }
static void Main(string[] args) { var connectionString = SecretConfiguration.ConnectionString; var optionsBuilder = new DbContextOptionsBuilder <Project0Context>(); optionsBuilder.UseSqlServer(connectionString); options = optionsBuilder.Options; var repo = new DataRepository(new Project0Context(options)); Lib.User currentUser; Console.WriteLine("Welcome to Pizza Manager!"); //Console.WriteLine("Press L to (L)oad data"); //Console.WriteLine("Press N for (N)ew data"); string input; //= Console.ReadLine().ToUpper(); //if (input.StartsWith('N')) //{ //Console.WriteLine("You selected New Data"); PrintMainMenu(); input = Console.ReadLine().ToUpper(); while (!input.StartsWith('Q')) { List <Lib.Location> posLoc = repo.GetLocations(); if (input.StartsWith('C') || input.StartsWith('U')) { Console.WriteLine("Enter First Name"); string firstName = Console.ReadLine(); Console.WriteLine("Enter Last Name"); string lastName = Console.ReadLine(); if (input.StartsWith('C')) { Console.WriteLine("Please enter default location"); foreach (var l in posLoc) { Console.WriteLine(l.Name); } input = Console.ReadLine(); Lib.Location defaultLocation = posLoc.Where(a => a.Name.Equals(input)).First(); currentUser = new Lib.User() { FirstName = firstName, LastName = lastName, DefaultLocation = defaultLocation }; //adding to database repo.AddUser(currentUser); //Users.Add(currentUser); } else { currentUser = repo.GetUser(firstName, lastName); } Console.WriteLine($"Welcome {currentUser.FirstName} {currentUser.LastName}"); Console.WriteLine("Press A to (A)dd Order"); Console.WriteLine("Press F to order (F)avorite"); Console.WriteLine("Press H to view Order History"); Console.WriteLine("Press B to go (B)ack to Main Menu"); input = Console.ReadLine().ToUpper(); while (!input.StartsWith('B')) { if (input.StartsWith('A')) { //List<Lib.Location> posLoc = repo.GetLocations(); Console.WriteLine("Possible Locations: "); foreach (var l in posLoc) { Console.Write(l.Name); if (currentUser.DefaultLocation.LocationId == l.LocationId) { Console.Write(" (default) "); } Console.WriteLine(); } Console.WriteLine("Enter the name of the restaurant you would like to order from"); input = Console.ReadLine(); Lib.Location chosenLocation = posLoc.Where(a => a.Name.Equals(input)).First(); //List < KeyValuePair<Pizza, int> > menu = chosenLocation.Inventory.ToList(); List <Lib.Pizza> menu = repo.GetPizzas(); Dictionary <Lib.Pizza, int> chosenPizzas = new Dictionary <Lib.Pizza, int>(); int numPressed; bool again = true; Console.WriteLine("Choose your pizza(s) to order"); for (int i = 0; i < menu.Count; i++) { Console.WriteLine($"Press {i} to choose {menu[i].Name}, Price: {menu[i].Price}"); } input = Console.ReadLine(); if (!int.TryParse(input, out numPressed)) { numPressed = 0; } while (again) { if (chosenPizzas.ContainsKey(menu[numPressed])) { chosenPizzas[menu[numPressed]] += 1; } else { chosenPizzas[menu[numPressed]] = 1; } Console.WriteLine("Add another pizza(s) to order or Press Q to finish order"); for (int i = 0; i < menu.Count; i++) { Console.WriteLine($"Press {i} to choose {menu[i].Name}, Price: {menu[i].Price}"); } input = Console.ReadLine(); again = int.TryParse(input, out numPressed); } //Console.WriteLine($"placing order for User {currentUser.UserId}"); //Console.WriteLine($"placing order for Location {chosenLocation.LocationId}"); Console.WriteLine("how many hours from now would you like to place the order"); input = Console.ReadLine(); int numHours = 0; int.TryParse(input, out numHours); Lib.Order ChosenOrder = new Lib.Order(chosenLocation, currentUser, DateTime.Now.AddHours(numHours), chosenPizzas); try { repo.AddOrder(ChosenOrder); Console.WriteLine("Order has been Placed"); } catch (Lib.BadOrderException e) { Console.WriteLine($"A problem has occured with your order: {e.Message}"); } //Console.WriteLine("number of pepperoni: "+ chosenLocation.Inventory[chosenLocation.Inventory.Keys.Where(a=>a.Name == "Pepperoni").First()]); repo.Save(); } else if (input.StartsWith('H')) { List <Lib.Order> orderHistory = repo.GetUserOrderHistory(currentUser); //Console.WriteLine(orderHistory.Count()); input = "A"; while (!input.StartsWith('Q')) { foreach (var o in orderHistory) { Console.WriteLine($"{o.User.FirstName},{o.User.LastName} \t {o.Location.Name} \t {o.OrderTime}"); foreach (var p in o.Contents) { Console.Write($"{p.Key.Name} - {p.Value}, "); } Console.WriteLine($"Total Cost: {o.Price()} \n"); } Console.WriteLine("Order History by (E)arliest, (L)atest, (C)heapest, (P)riciest, or Q to (Q)uit"); input = Console.ReadLine().ToUpper(); if (input.StartsWith('E')) { orderHistory = Lib.OrderManager.EarliestOrderedHistory(orderHistory); } else if (input.StartsWith('L')) { orderHistory = Lib.OrderManager.LatestOrderedHistory(orderHistory); } else if (input.StartsWith('C')) { orderHistory = Lib.OrderManager.CheapestOrderedHistory(orderHistory); } else if (input.StartsWith('P')) { orderHistory = Lib.OrderManager.ExpensiveOrderedHistory(orderHistory); } } } else if (input.StartsWith('F')) { Lib.Order o = currentUser.SuggestedOrder(repo.GetUserOrderHistory(currentUser)); try { repo.AddOrder(o); Console.WriteLine("Order has been Placed"); } catch (Lib.BadOrderException e) { Console.WriteLine($"A problem has occured with your order: {e.Message}"); } } Console.WriteLine("Press A to (A)dd Order"); Console.WriteLine("Press F to order (F)avorite"); Console.WriteLine("Press H to view Order History"); Console.WriteLine("Press B to go (B)ack to Main Menu"); input = Console.ReadLine().ToUpper(); } } else if (input.StartsWith('L') || input.StartsWith('O')) { Lib.Location currentLocation; if (input.StartsWith('O')) { Console.WriteLine("Enter the name of your location"); input = Console.ReadLine(); string locName = input; Console.WriteLine("choose your inventory package plan"); Console.WriteLine("press 1 for beginner package: 5 pepperoni, 5 sausage, 5 Bell Pepper, 5 Olives"); Console.WriteLine("press 2 for medium package: 10 pepperoni, 10 sausage, 10 Bell Pepper, 10 Olives"); Console.WriteLine("press 3 advanced package: 15 pepperoni, 15 sausage, 15 Bell Pepper, 15 Olives"); input = Console.ReadLine(); int level = int.Parse(input); Dictionary <Lib.Ingredient, int> tempInv = new Dictionary <Lib.Ingredient, int>(); tempInv[new Lib.Ingredient("Pepperoni")] = 5 * level; tempInv[new Lib.Ingredient("Sausage")] = 5 * level; tempInv[new Lib.Ingredient("Bell Pepper")] = 5 * level; tempInv[new Lib.Ingredient("Olives")] = 5 * level; currentLocation = new Lib.Location() { Name = locName, Inventory = tempInv }; repo.AddLocation(currentLocation); } else { Console.WriteLine("enter the name of the location"); input = Console.ReadLine(); currentLocation = repo.GetLocation(input); } Console.WriteLine($"Welcome {currentLocation.Name}"); Console.WriteLine("Press H to view Order History"); Console.WriteLine("Press I to view current Inventory"); Console.WriteLine("Press B to go back to Main Menu"); input = Console.ReadLine().ToUpper(); while (!input.StartsWith('B')) { if (input.StartsWith('I')) { foreach (var pair in currentLocation.Inventory) { Console.WriteLine($"Ingredient: {pair.Key.Name}, Remaining: {pair.Value}"); } } else if (input.StartsWith('H')) { //List<Lib.Order> orderHistory = repo.GetLocationOrderHistory(currentLocation); ////Console.WriteLine(orderHistory.Count()); //foreach (var o in orderHistory) //{ // Console.WriteLine($"{o.User.FirstName},{o.User.LastName} \t {o.Location.Name}"); // foreach (var p in o.Contents) // { // Console.Write($"{p.Key.Name} - {p.Value}, "); // } // Console.WriteLine($"Total Cost: {o.Price()} \n"); //} List <Lib.Order> orderHistory = repo.GetLocationOrderHistory(currentLocation); //Console.WriteLine(orderHistory.Count()); input = "A"; while (!input.StartsWith('Q')) { foreach (var o in orderHistory) { Console.WriteLine($"{o.User.FirstName},{o.User.LastName} \t {o.Location.Name} \t {o.OrderTime}"); foreach (var p in o.Contents) { Console.Write($"{p.Key.Name} - {p.Value}, "); } Console.WriteLine($"Total Cost: {o.Price()} \n"); } Console.WriteLine("Order History by (E)arliest, (L)atest, (C)heapest, (P)riciest, or Q to (Q)uit"); input = Console.ReadLine().ToUpper(); if (input.StartsWith('E')) { orderHistory = Lib.OrderManager.EarliestOrderedHistory(orderHistory); } else if (input.StartsWith('L')) { orderHistory = Lib.OrderManager.LatestOrderedHistory(orderHistory); } else if (input.StartsWith('C')) { orderHistory = Lib.OrderManager.CheapestOrderedHistory(orderHistory); } else if (input.StartsWith('P')) { orderHistory = Lib.OrderManager.ExpensiveOrderedHistory(orderHistory); } } } Console.WriteLine("Press H to view Order History"); Console.WriteLine("Press I to view current Inventory"); Console.WriteLine("Press B to go back to Main Menu"); input = Console.ReadLine().ToUpper(); } } PrintMainMenu(); input = Console.ReadLine().ToUpper(); } }