public static PizzaTopping DomPizzaTopping2PizzaTopping(DomPizzaTopping inTopping) { PizzaTopping outTopping = new PizzaTopping() { ToppingId = inTopping.ToppingId }; return(outTopping); }
public void TestPizzaToppingMap() { //Arrange DomPizzaTopping testDPT = new DomPizzaTopping(0); //Act var testPT = DataDomainMapper.DomPizzaTopping2PizzaTopping(testDPT); //Assert Assert.IsInstanceOfType(testPT, typeof(PizzaTopping)); }
public IActionResult Checkout() { string username = HttpContext.Session.GetString("Username"); if (string.IsNullOrEmpty(username)) { return(View("WarningMessage", "You must be logged in to place an order.")); } int locId = (int)HttpContext.Session.GetInt32("LocationId"); OrderModel order = TempData.get("Order"); if (order.Pizzas.Count == 0) { return(View("WarningMessage", "Can't place an order with no pizzas. Please add pizzas to your order.")); } List <DomPizza> pList = new List <DomPizza>(); foreach (var p in order.Pizzas) { List <DomPizzaTopping> ptList = new List <DomPizzaTopping>(); foreach (var t in p.toppings) { int id = PRepo.GetToppingID(t); DomPizzaTopping pt = new DomPizzaTopping(id); ptList.Add(pt); } DomPizza pizza = new DomPizza(p.Crust, p.Size, ptList); pList.Add(pizza); } DomOrder DOrder = new DomOrder(username, locId, DateTime.Now, 0, pList); DomOrder lastOrder = ORepo.GetMostRecentOrder(URepo.GetUser(username)); DateTime lastDate = (lastOrder != null) ? lastOrder.OrderDate : DateTime.MinValue; if (DOrder.Within24Hours(lastDate) && DOrder.LocationId != lastOrder.LocationId) { TempData.Keep(); return(View("WarningMessage", "You ordered at a different location within the past 24 hours. Please order there again or wait to order from us.")); } if (DOrder.Within2Hours(lastDate)) { TempData.Keep(); return(View("WarningMessage", "You ordered within the last two hours.")); } ORepo.AddOrder(DOrder); TempData.Remove("Order"); return(RedirectToAction("Index", "Home")); }
public IActionResult AddToOrder(Dictionary <string, int> toppings) { int crust = (int)TempData["PizzaCrust"]; int size = (int)TempData["PizzaSize"]; List <DomPizzaTopping> inToppings = new List <DomPizzaTopping>(); foreach (KeyValuePair <string, int> top in toppings) { for (int i = 0; i < top.Value; i++) { int id = PRepo.GetToppingID(top.Key); DomPizzaTopping pt = new DomPizzaTopping(id); inToppings.Add(pt); } } DomPizza pizza = new DomPizza(crust, size, inToppings); PizzaModel inPizza = new PizzaModel(); inPizza.Cost = pizza.Cost; inPizza.Crust = pizza.Crust; inPizza.Size = pizza.Size; foreach (var t in pizza.PizzaToppings) { inPizza.toppings.Add(PRepo.GetTopping(t.ToppingId).ToppingName); } OrderModel order = TempData.get("Order"); if (order == null) { return(View("WarningMessage", "Session timed out.")); } order.cost += inPizza.Cost; order.Pizzas.Add(inPizza); TempData.put("Order", order); return(RedirectToAction("Order")); }
public static DomPizzaTopping PizzaTopping2DomPizzaTopping(PizzaTopping inPt) { DomPizzaTopping outPt = new DomPizzaTopping(inPt.ToppingId); return(outPt); }
static void AddPizza() { if (currOrder.IsAtMaxPizzas()) { Console.WriteLine("You have reached the limit on pizzas at 100 pizzas. Please order and try again in 2 hours."); WaitForInput(); return; } DomPizza newPizza; while (true) { PizzaCrust crust; while (true) { Console.Clear(); Console.WriteLine("Select a Crust or type \'return\' to return to the order menu: "); foreach (var c in Enum.GetValues(typeof(PizzaCrust))) { Console.WriteLine($"({Convert.ToInt32(c)}) {c}"); } string input = Console.ReadLine(); if (input == "return") { return; } int choice; if (!int.TryParse(input, out choice)) { Console.WriteLine("Please input a number."); WaitForInput(); } else if (Enum.IsDefined(typeof(PizzaCrust), choice)) { crust = (PizzaCrust)choice; break; } else { Console.WriteLine("Please select a valid Crust."); WaitForInput(); } } PizzaSize size; while (true) { Console.Clear(); Console.WriteLine("Select a Size or type \'return\' to return to the order menu: "); foreach (var c in Enum.GetValues(typeof(PizzaSize))) { Console.WriteLine($"({Convert.ToInt32(c)}) {c}"); } string input = Console.ReadLine(); if (input == "return") { return; } int choice; if (!int.TryParse(input, out choice)) { Console.WriteLine("Please input a number."); WaitForInput(); } else if (Enum.IsDefined(typeof(PizzaSize), choice)) { size = (PizzaSize)choice; break; } else { Console.WriteLine("Please select a valid Size."); WaitForInput(); } } List <DomPizzaTopping> toppings = new List <DomPizzaTopping>(); while (true) { Console.Clear(); Console.WriteLine("Select a topping or type \'none\' if you want no toppings or \'return\' to cancel"); List <DomTopping> topList = pRepo.GetToppingList(); int i = 0; foreach (var top in topList) { Console.WriteLine($"({i}) {top.ToppingName}"); i++; } string input = Console.ReadLine(); if (input == "return") { return; } if (input == "none") { break; } int choice; if (!int.TryParse(input, out choice)) { Console.WriteLine("Please input a number."); WaitForInput(); } else if (choice >= topList.Count || choice < 0) { Console.WriteLine("Please select a valid topping."); WaitForInput(); } else { DomPizzaTopping ptopping = new DomPizzaTopping(choice); toppings.Add(ptopping); if (toppings.Count < 5) { Console.Clear(); Console.WriteLine("Would you like to add more toppings? (y/n)"); input = Console.ReadLine(); if (input != "") { char inp = Char.ToLower(input[0]); if (inp == 'n') { break; } } } else { break; } } } newPizza = new DomPizza((int)crust, (int)size, toppings); currOrder.AddPizza(newPizza); if (currOrder.IsAtMaxPizzas()) { Console.Clear(); Console.WriteLine("Would you like to add another pizza? (y/n)"); string input = Console.ReadLine(); if (input != "") { char inp = Char.ToLower(input[0]); if (inp == 'n') { break; } } } else { break; } } }