public List <DomPizzaTopping> GetPizzaToppings(DomPizza p) { List <PizzaTopping> inPizzaToppings = _db.PizzaTopping.Where <PizzaTopping>(pt => pt.PizzaId == p.PizzaID).ToList(); List <DomPizzaTopping> outPizzaToppings = new List <DomPizzaTopping>(); foreach (var pt in inPizzaToppings) { outPizzaToppings.Add(DataDomainMapper.PizzaTopping2DomPizzaTopping(pt)); } return(outPizzaToppings); }
public void CreationTest() { //Arrange List <DomPizzaTopping> toppings = new List <DomPizzaTopping>(); //Act DomPizza testPizza = new DomPizza(0, 0, toppings); //Assert Assert.IsInstanceOfType(testPizza, typeof(DomPizza)); }
public static DomPizza Pizza2DomPizz(Pizza inPizza) { List <DomPizzaTopping> domPTs = new List <DomPizzaTopping>(); foreach (var pt in inPizza.PizzaTopping) { domPTs.Add(PizzaTopping2DomPizzaTopping(pt)); } DomPizza outPizza = new DomPizza(inPizza.Crust, inPizza.Size, domPTs); outPizza.PizzaID = inPizza.Id; return(outPizza); }
public void CostTest() { //Arrange List <DomPizzaTopping> top1 = new List <DomPizzaTopping>(); top1.Add(new DomPizzaTopping()); top1.Add(new DomPizzaTopping()); List <DomPizzaTopping> top2 = new List <DomPizzaTopping>(); top2.Add(new DomPizzaTopping()); top2.Add(new DomPizzaTopping()); top2.Add(new DomPizzaTopping()); List <DomPizzaTopping> top3 = new List <DomPizzaTopping>(); top3.Add(new DomPizzaTopping()); top3.Add(new DomPizzaTopping()); top3.Add(new DomPizzaTopping()); top3.Add(new DomPizzaTopping()); top3.Add(new DomPizzaTopping()); decimal result1; decimal result2; decimal result3; decimal result4; decimal result5; decimal result6; //Act DomPizza p1 = new DomPizza((int)PizzaCrust.Standard, (int)PizzaSize.Medium, top1); DomPizza p2 = new DomPizza((int)PizzaCrust.Handtossed, (int)PizzaSize.Personal, top1); DomPizza p3 = new DomPizza((int)PizzaCrust.Cauliflower, (int)PizzaSize.Personal, top1); DomPizza p4 = new DomPizza((int)PizzaCrust.Standard, (int)PizzaSize.Large, top1); DomPizza p5 = new DomPizza((int)PizzaCrust.Standard, (int)PizzaSize.Medium, top2); DomPizza p6 = new DomPizza((int)PizzaCrust.Standard, (int)PizzaSize.Medium, top3); result1 = p1.Cost; result2 = p2.Cost; result3 = p3.Cost; result4 = p4.Cost; result5 = p5.Cost; result6 = p6.Cost; //Assert Assert.AreEqual(10m, result1); Assert.AreEqual(6.5m, result2); Assert.AreEqual(7m, result3); Assert.AreEqual(15m, result4); Assert.AreEqual(10.25m, result5); Assert.AreEqual(10.75m, result6); }
public static Pizza DomPizza2Pizza(DomPizza inPizza) { Pizza outPizza = new Pizza() { Crust = inPizza.Crust, Size = inPizza.Size, Cost = inPizza.Cost }; foreach (var pt in inPizza.PizzaToppings) { outPizza.PizzaTopping.Add(DomPizzaTopping2PizzaTopping(pt)); } return(outPizza); }
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 void TestPizzaMap() { //Arrange DomPizza testDPizza1 = new DomPizza(0, 0, new List <DomPizzaTopping>()); List <DomPizzaTopping> testList = new List <DomPizzaTopping>(); testList.Add(new DomPizzaTopping(0)); DomPizza testDPizza2 = new DomPizza(0, 0, testList); //Act var testPizza1 = DataDomainMapper.DomPizza2Pizza(testDPizza1); var testPizza2 = DataDomainMapper.DomPizza2Pizza(testDPizza2); //Assert Assert.IsInstanceOfType(testPizza1, typeof(Pizza)); Assert.IsInstanceOfType(testPizza2, typeof(Pizza)); }
public void RemovePizzaTest() { //Arrange DomOrder testOrder1 = new DomOrder(); DomPizza pizza1 = new DomPizza(0, 0, new List <DomPizzaTopping>()); testOrder1.AddPizza(pizza1); DomOrder testOrder2 = new DomOrder(); testOrder2.AddPizza(new DomPizza(0, 0, new List <DomPizzaTopping>())); //Act testOrder1.RemovePizza(pizza1); testOrder2.RemovePizza(0); //Assert Assert.AreEqual(0, testOrder1.Pizzas.Count); Assert.AreEqual(0, testOrder2.Pizzas.Count); }
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")); }
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; } } }