public static string BeginOrder(string name, User u, Location l, PizzaStoreRepository repo) { Console.WriteLine("View your order history?"); string ans = Console.ReadLine(); if (ans == "y") { repo.PrintOrderHistory(repo.GetOrdersByUser(u)); } Order o = new Order { User = u, UserID = repo.GetUserID(u), OrderTime = DateTime.Now, LocationID = l.LocationID, NumPizza = 0, Price = 0 }; repo.AddOrder(o); repo.Save(); o.Id = repo.GetMostRecentOrderID(); //First check if the user ordered within 2 hours //if ((repo.GetMostRecentOrderByUser(o).OrderTime - o.OrderTime).TotalMinutes < 120) //{ // return $"No, {u.FirstName}, we can't prcoess your order since you have ordered within the past 2 hours."; //} if (l.UserExistInOrderHistory(l.OrderHistory, name)) { //if the user exists, give a suggestion based on the last order... Pizza Suggested = Location.SortOrderHistory(l.OrderHistoryByUser(l.OrderHistory, name), "latest")[0].PizzaList[0]; Console.WriteLine($"You have ordered a {Suggested.PizzaSize} with {Suggested.Toppings} in the past. Would you like to add this to your order? [y/n]"); string answ = Console.ReadLine(); if (answ == "y") { o.PizzaList.Add(Suggested); o.NumPizza++; o.Price += Suggested.Price; Console.WriteLine("Would you like to order more pizzas? [y/n]"); string more = Console.ReadLine(); if (more == "n") { FinalizeOrder(l, o, repo); } } } //Now regardless of user in system or not they can order while (o.Price < 500) { if (o.NumPizza > 11) { Console.WriteLine("Cannot order more pizza since you are ordering more than 12 pizzas."); return("Failed to place order"); } //Actually begin to order Pizza p = new Pizza() { OrderID = repo.GetMostRecentOrderID(), PizzaSize = "A" }; Console.WriteLine("Please select the size of your pizza [S/M/L]"); p.PizzaSize = Console.ReadLine(); //Update pizza price based on size if (p.PizzaSize == "S") { p.Price += 10; p.PizzaSize = "S"; } if (p.PizzaSize == "M") { p.Price += 15; p.PizzaSize = "M"; } if (p.PizzaSize == "L") { p.Price += 20; p.PizzaSize = "L"; } Console.WriteLine("We have the following toppings:"); l.Toppings.ForEach(Console.WriteLine); for (var i = 0; i < l.Toppings.Count; i++) { Console.WriteLine($"Add {l.Toppings[i]}? [y/n]"); AddTopping(l, p, l.Toppings[i], Console.ReadLine(), repo); } repo.AddPizza(p); repo.Save(); p.Id = repo.GetMostRecentPizza().Id; o.PizzaList.Add(p); o.Price += p.Price; o.NumPizza++; Console.WriteLine($"You currently have {o.NumPizza} pizza(s). Would you like to order more? [y/n]"); string b = Console.ReadLine(); if (b == "n") { break; } } FinalizeOrder(l, o, repo); return("Order Finished."); }
public ActionResult MakeOrder(IFormCollection viewCollection, MVCustomer cust) { Random rdm = new Random(); int ONum = rdm.Next(1, 1000000); int UseridTD = int.Parse(TempData.Peek("custid").ToString()); string LocationTD = TempData.Peek("locationName").ToString(); string NameTD = TempData.Peek("firstname").ToString(); string LastnameTD = TempData.Peek("lastname").ToString(); string PhoneTD = TempData.Peek("phone").ToString(); if (Count == 12) { ViewData["msg"] = "ERROR YOU CANNOT ORDER MORE THAN 12 PIZZAS!!!!! "; return(RedirectToAction(nameof(MakeOrder))); } string selectedSize = viewCollection["SelectedSize"]; string selectedTopping = viewCollection["SelectedTopping"]; string selectedCrust = viewCollection["SelectedCrust"]; if (selectedSize == "Small") { price = 5.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 5.00; TempData["order_total"] = total; } else if (selectedSize == "Medium") { price = 10.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 10.00; TempData["order_total"] = total; } else if (selectedSize == "Large") { price = 15.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 15.00; TempData["order_total"] = total; } else if (selectedCrust == "1") { price = .50; total = int.Parse(TempData.Peek("order_total").ToString()); total += .50; TempData["order_total"] = total; } else { price = 20.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 20.00; TempData["order_total"] = total; } if (TempData.Peek("Count").ToString() == "1") { Count = 1; } else { Count = int.Parse(TempData.Peek("Count").ToString()); } if (Count < 2)//only if the order is new is going to be created { //add order Repo.AddOrders(ONum, NameTD, LastnameTD, LocationTD, price, total, DateTime.Now, "T'Challa Slice", PhoneTD); Repo.SaveChanges(); } bool PG = bool.Parse(selectedCrust); Repo.AddPizza(selectedSize, selectedTopping, PG, ONum); Repo.SaveChanges(); // increment counter to know next time, that this is not a new order. Count++; TempData["Count"] = Count; var orderId = Repo.GetOrders().FirstOrDefault(x => x.CustomerPhoneNumber == PhoneTD && x.CustomerName == NameTD); TempData["orderId"] = orderId.Id; return(RedirectToAction(nameof(MakeOrder))); }