public bool AddNewPizza(RawNewPizza obj) { AStore curStore = storeRepo.FindStore(obj.ID); if (curStore is null) { return(false); } Crust newCrust = storeRepo.GetCrustByID(obj.Crust.ID); if (newCrust is null) { return(false); } List <Topping> toppings = new List <Topping>(); foreach (RawComp rc in obj.AllToppings) { Topping t = storeRepo.GetToppingByID(rc.ID); if (t is null) { return(false); } toppings.Add(t); } BasicPizza newPizza = mapper.RawToBasicPizzaMapper(obj, newCrust, toppings); if (!storeRepo.AddPizzaToStore(obj.ID, newPizza)) { return(false); } return(true); }
public static void Main(string[] args) { #if debug IPizza bp = BasicPizza.TakeOrder(4, 2); var bpc = bp.TotalCost(); if (bp != null) { bp = new TomatoSaucePizza(bp); var tsc = bp.TotalCost(); bp = new MozarellaCheesePizza(bp); var mcc = bp.TotalCost(); bp = new HamPizza(bp); var hc = bp.TotalCost(); } #endif #if debug using (var scope = host.Services.CreateScope()) using (var context = scope.ServiceProvider.GetService <AppDbContext>()) { try { DBInitializer.Initialize(context); context.Database.EnsureCreated(); } catch (Exception) { throw; } } #endif var host = BuildWebHost(args); host.Run(); }
public void Test_AddPizzaToStore() { var options = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb2") .Options; AStore store = new AStore(); BasicPizza newPizza = new BasicPizza(); newPizza.Type = "Test Pizza"; using (var context = new StoreContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add <AStore>(store); context.SaveChanges(); } using (var context = new StoreContext(options)) { StoreRepository storeRepo = new StoreRepository(context); storeRepo.AddPizzaToStore(store.StoreID, newPizza); var pres = context.BasicPizza.SingleOrDefault(p => p.Type == newPizza.Type); Assert.Equal(pres.Type, newPizza.Type); } }
/// <summary> /// Maps a RawPizza from user to BasicPizza /// </summary> /// <param name="obj">RawPizza from user</param> /// <param name="newCrust">Crust obj for BasicPizza</param> /// <param name="toppings">List of Topping objects</param> /// <returns></returns> internal BasicPizza RawToBasicPizzaMapper(RawNewPizza obj, Crust newCrust, List <Topping> toppings) { BasicPizza newPizza = new BasicPizza(); newPizza.Type = obj.Name; newPizza.Crust = newCrust; newPizza.Toppings = toppings; return(newPizza); }
/// <summary> /// Uses the new order request model to calculate the cost for each pizza and /// their toppings with the distance for delivery as total cost factor. /// </summary> /// <param name="order">Represents a pizza order request</param> /// <returns>A price for the order, description of the order, order ID, total pizzas /// and the delivery cost.</returns> public static OrderVm GetPriceQuoteForCustomerOrder(NewOrderVm order) { IPizza appliedTopping = BasicPizza.TakeOrder(order.CustomPizzas.Count, order.Distance); if (appliedTopping == null) { return(new OrderVm()); } List <string> itemDescriptions = new List <string>(); foreach (var cp in order.CustomPizzas) { string desc = cp.Toppings.Count > 0 ? "Yummy crust pizza with" : "Yummy crust pizza"; foreach (string topping in cp.Toppings) { switch (topping.ToUpper()) { case "TOMATOSAUCE": appliedTopping = new TomatoSaucePizza(appliedTopping); desc += appliedTopping.GetDescription(); break; case "MOZARELLACHEESE": appliedTopping = new MozarellaCheesePizza(appliedTopping); desc += appliedTopping.GetDescription(); break; case "HAM": appliedTopping = new HamPizza(appliedTopping); desc += appliedTopping.GetDescription(); break; case "KEBAB": appliedTopping = new KebabPizza(appliedTopping); desc += appliedTopping.GetDescription(); break; default: break; } } itemDescriptions.Add(desc); } return(new OrderVm() { TotalCost = Math.Round(appliedTopping.TotalCost(), 2), TotalPizzas = order.CustomPizzas.Count, OrderedItems = itemDescriptions }); }
/// <summary> /// Adds the new pizza into the database /// Then adds the new pizza to the preset of the store afterwards /// </summary> /// <param name="id">Store ID</param> /// <param name="bp">New Pizza</param> /// <returns></returns> public bool AddPizzaToStore(Guid id, BasicPizza bp) { var getStore = context.Stores.Include(s => s.PresetPizzas).SingleOrDefault(n => Guid.Equals(n.StoreID, id)); if (getStore is null) { return(false); } getStore.PresetPizzas.Add(bp); context.Entry(bp).State = EntityState.Added; context.BasicPizza.Add(bp); context.SaveChanges(); return(true); }
private void InitFreddyStore() { Dictionary <string, decimal> toppings = new Dictionary <string, decimal>(); toppings.Add("onions", 0.75m); toppings.Add("tomatoes", 1.50m); toppings.Add("spinach", 0.57m); toppings.Add("mushroom", 0.45m); toppings.Add("olive", 0.25m); toppings.Add("peppers", 0.30m); toppings.Add("pineapple", 0.50m); Dictionary <string, decimal> sizes = new Dictionary <string, decimal>(); sizes.Add("medium", 5.00m); sizes.Add("large", 6.00m); Dictionary <string, decimal> crusts = new Dictionary <string, decimal>(); crusts.Add("regular", 0.50m); crusts.Add("hand-tossed", 1.00m); crusts.Add("thin", 0.50m); //3, 100.00, 20 AStore tempStore = InitNewStore("Freddy's Pizza Store", 10, 3, 100.00m, toppings, crusts, sizes); BasicPizza tempP = new BasicPizza(); tempP.Type = "Basic Veggie Pizza"; tempP.AddCrust(tempStore.CrustList[0]); tempP.AddTopping(tempStore.ToppingsList[0]); tempP.AddTopping(tempStore.ToppingsList[1]); tempP.AddTopping(tempStore.ToppingsList[4]); tempP.AddTopping(tempStore.ToppingsList[6]); //tempP.CalculatePrice(); tempStore.PresetPizzas.Add(tempP); context.Add <AStore>(tempStore); context.SaveChanges(); }
/// <summary> /// CURRENTLY NOT USED /// Maps all the RawPizzas from RawOrder to BasicPizzas in Order /// Goes through all size/crust/toppings and creates an appropriate basic pizza /// </summary> /// <param name="newOrder">Order containing List of BasicPizzas</param> /// <param name="obj">Order containing List of RawPizzas</param> /// <param name="storeCrust">List of store's crusts</param> /// <param name="storeSize">List of store's sizes</param> /// <param name="storeToppings">List of store's toppings</param> public void PizzaMapper(Order newOrder, RawOrder obj, List <Crust> storeCrust, List <Size> storeSize, List <Topping> storeToppings) { foreach (RawPizza rp in obj.PizzaList) { BasicPizza bp = new BasicPizza(); bp.Type = rp.Name; bp.PizzaPrice = rp.Price; foreach (Crust c in storeCrust) { if (c.PizzaType.Name == rp.Crust) { bp.Crust = c; break; } } foreach (Size s in storeSize) { if (s.PizzaType.Name == rp.Size) { bp.Size = s; break; } } foreach (string rpt in rp.Toppings) { foreach (Topping t in storeToppings) { if (t.PizzaType.Name == rpt) { bp.Toppings.Add(t); break; } } } newOrder.Pizzas.Add(bp); } }
private void InitNewYorkStore() { Random rng = new Random(); Dictionary <string, decimal> toppings = new Dictionary <string, decimal>(); toppings.Add("beef", (rng.Next(1, 101) / 100.0m)); toppings.Add("chicken", (rng.Next(1, 101) / 100.0m)); toppings.Add("ham", (rng.Next(1, 101) / 100.0m)); toppings.Add("mushroom", (rng.Next(1, 101) / 100.0m)); toppings.Add("olive", (rng.Next(1, 101) / 100.0m)); toppings.Add("peppers", (rng.Next(1, 101) / 100.0m)); toppings.Add("pineapple", (rng.Next(1, 101) / 100.0m)); toppings.Add("pepporoni", (rng.Next(1, 101) / 100.0m)); toppings.Add("salami", (rng.Next(1, 101) / 100.0m)); toppings.Add("sausage", (rng.Next(1, 101) / 100.0m)); toppings.Add("meat ball", (rng.Next(1, 101) / 100.0m)); toppings.Add("anchovies", (rng.Next(1, 101) / 100.0m)); Dictionary <string, decimal> sizes = new Dictionary <string, decimal>(); sizes.Add("small", 4.50m); sizes.Add("large", 5.50m); sizes.Add("extra large", 6.50m); Dictionary <string, decimal> crusts = new Dictionary <string, decimal>(); crusts.Add("regular", 1.00m); crusts.Add("hand-tossed", 1.00m); crusts.Add("thin", 1.00m); //7, 250.00, 50) AStore tempStore = InitNewStore("NewYork Pizza Store", 50, 7, 200.0m, toppings, crusts, sizes); // /*Meat*/ BasicPizza tempP = new BasicPizza(); tempP.Type = "Meat Pizza"; tempP.AddCrust(tempStore.CrustList[0]); tempP.AddTopping(tempStore.ToppingsList[0]); tempP.AddTopping(tempStore.ToppingsList[1]); tempP.AddTopping(tempStore.ToppingsList[2]); tempP.AddTopping(tempStore.ToppingsList[6]); tempP.AddTopping(tempStore.ToppingsList[8]); //tempP.CalculatePrice(); tempStore.PresetPizzas.Add(tempP); /*Hawaiian*/ tempP = new BasicPizza(); tempP.Type = "Hawaiian Pizza"; tempP.AddCrust(tempStore.CrustList[0]); tempP.AddTopping(tempStore.ToppingsList[2]); tempP.AddTopping(tempStore.ToppingsList[5]); tempP.AddTopping(tempStore.ToppingsList[7]); //tempP.CalculatePrice(); tempStore.PresetPizzas.Add(tempP); /*Deluxe*/ tempP = new BasicPizza(); tempP.Type = "Deluxe Pizza"; tempP.AddCrust(tempStore.CrustList[0]); tempP.AddTopping(tempStore.ToppingsList[6]); tempP.AddTopping(tempStore.ToppingsList[9]); tempP.AddTopping(tempStore.ToppingsList[3]); tempP.AddTopping(tempStore.ToppingsList[5]); tempP.AddTopping(tempStore.ToppingsList[11]); //tempP.CalculatePrice(); tempStore.PresetPizzas.Add(tempP); context.Add <AStore>(tempStore); context.SaveChanges(); }