/// <summary> /// Map DBPizza => APizza /// Uses enum to determine which crust class to return. /// Note: premade pizza classes have constructors to set all variables properly. /// Therefore, they do not need any data tobe passed innto them. /// Custom pizza however only has 1 constructor that requires crust, size, and toppings /// to be passed into them. /// </summary> /// <param name="entity"></param> /// <returns></returns> public APizza Map(DBPizza entity) { APizza pizza; switch (entity.PIZZA) { case PIZZAS.CUSTOM: ACrust crust = mapperCrust.Map(entity.DBCrust); ASize size = mapperSize.Map(entity.DBSize); List <ATopping> toppings = new List <ATopping>(); entity.DBPlacedToppings.ToList().ForEach(placedTopping => toppings.Add(mapperTopping.Map(placedTopping.Topping))); pizza = new CustomPizza(crust, size, toppings); break; case PIZZAS.HAWAIIAN: pizza = new HawaiianPizza(mapperSize.Map(entity.DBSize)); break; case PIZZAS.MEAT: pizza = new MeatPizza(mapperSize.Map(entity.DBSize)); break; case PIZZAS.VEGAN: pizza = new VeganPizza(mapperSize.Map(entity.DBSize)); break; default: throw new ArgumentException("Pizza not recognized. Pizza could not be mapped properly"); } pizza.CalculatePrice(); pizza.ID = entity.ID; return(pizza); }
/// <summary> /// Map DBPizza => APizza /// Uses enum to determine which crust class to return. /// Note: premade pizza classes have constructors to set all variables properly. /// Therefore, they do not need any data tobe passed innto them. /// Custom pizza however only has 1 constructor that requires crust, size, and toppings /// to be passed into them. /// </summary> /// <param name="entity"></param> /// <returns></returns> public APizza Map(DBPizza entity) { APizza pizza; switch (entity.PIZZA) { case Entities.EntityModels.PIZZAS.CUSTOM: Crust crust = mapperCrust.Map(entity.DBCrust); Size size = mapperSize.Map(entity.DBSize); List <Topping> toppings = new List <Topping>(); entity.DBToppings.ForEach(Topping => toppings.Add(mapperTopping.Map(Topping))); pizza = new CustomPizza(crust, size, toppings); break; case Entities.EntityModels.PIZZAS.HAWAIIAN: pizza = new HawaiianPizza(); break; case Entities.EntityModels.PIZZAS.MEAT: pizza = new MeatPizza(); break; case Entities.EntityModels.PIZZAS.VEGAN: pizza = new VeganPizza(); break; default: throw new ArgumentException("Size not recognized. Size could not be mapped properly"); } return(pizza); }
public APizza Map(Pizza model) { APizza pizza; switch (model.PizzaType) { case Entities.PIZZA_TYPE.Meat: pizza = new MeatPizza(); break; case Entities.PIZZA_TYPE.Vegan: pizza = new VeganPizza(); break; case Entities.PIZZA_TYPE.Custom: pizza = new CustomPizza(); break; default: throw new ArgumentException("PizzaMapper encountered an unknown type when mapping from DB Model to Domain Model"); } pizza.Crust = crustMapper.Map(model.Crust); pizza.Size = sizeMapper.Map(model.Size); List <Domain.Models.Topping> toppings = new List <Domain.Models.Topping>(); model.Toppings.ForEach(topping => toppings.Add(toppingMapper.Map(topping))); pizza.Toppings = toppings; //pizza.Price = model.Price; return(pizza); }
public static void SeedData() { // For some reason EF doesn't like this // if a command runs that doesn't update a row // EF will completely error out and stop all transactionsg //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Toppings_ToppingType on dbo.Toppings SET ( IGNORE_DUP_KEY = ON )"); //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Crusts_CrustType on dbo.Crusts SET ( IGNORE_DUP_KEY = ON )"); //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Stores_Name on dbo.Stores SET ( IGNORE_DUP_KEY = ON )"); //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Sizes_SizeType on dbo.Sizes SET ( IGNORE_DUP_KEY = ON )"); //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Customers_Name on dbo.Customers SET ( IGNORE_DUP_KEY = ON )"); OrderRepository orderRepository = new OrderRepository(DbContextSingleton.Instance.Context); Customer cust = new Customer("Nick"); //AStore store = new ChicagoStore(); //store.Name = "Test Chicago Store 2"; AStore store = _storeSingleton.Stores[0]; Order order = new Order(); order.Store = store; order.Customer = cust; APizza pizza1 = new MeatPizza(); APizza pizza2 = new VeganPizza(); order.Pizzas = new List <APizza>() { pizza1, pizza2 }; orderRepository.Add(order); /* * pizza.Size = new LargeSize(); * pizza.Toppings = new List<Topping>(); * pizza.Toppings.Add(new BaconTopping()); * pizza.Toppings.Add(new OnionTopping()); * order.Store.Name = "Test Store 2"; * orderRepository.Add(order); */ /* * public Store Store { get; set; } * public Customer Customer { get; set; } * public List<Pizza> Pizzas { get; set; } * public decimal TotalPrice { get; set; } * public DateTime OrderTime { get; set; } * */ }
public ActionResult <APizza> GetPizzaInfo(PIZZAS PIZZA, SIZES SIZE) { APizza pizza; ASize size; switch (SIZE) { case SIZES.SMALL: size = new SmallSize(); break; case SIZES.MEDIUM: size = new MediumSize(); break; case SIZES.LARGE: size = new LargeSize(); break; default: return(StatusCode(400, "Size not recognized")); } switch (PIZZA) { case PIZZAS.MEAT: pizza = new MeatPizza(size); break; case PIZZAS.HAWAIIAN: pizza = new HawaiianPizza(size); break; case PIZZAS.VEGAN: pizza = new VeganPizza(size); break; case PIZZAS.CUSTOM: return(StatusCode(400, "You entered a custom pizza without providing the crust or toppings")); default: return(StatusCode(400, "Size not recognized")); } pizza.CalculatePrice(); return(Ok(pizza)); }
public APizza Map(Pizza model) { APizza pizza; switch (model.PizzaType) { case PIZZA_TYPE.Meat: pizza = new MeatPizza(); break; case PIZZA_TYPE.Vegan: pizza = new VeganPizza(); break; case PIZZA_TYPE.Custom: pizza = new CustomPizza(); break; default: throw new ArgumentException("PizzaMapper encountered an unknown type when mapping from DB Model to Domain Model"); } pizza.Crust = crustMapper.Map(model.Crust); pizza.Size = sizeMapper.Map(model.Size); List <ATopping> toppings = new List <ATopping>(); model.PizzaToppings.ToList().ForEach(pt => { for (int i = 0; i < pt.Amount; i++) { toppings.Add(toppingMapper.Map(pt.Topping)); } }); pizza.Toppings = toppings; // TODO: check why this was commented out?????????? //pizza.Price = model.Price; pizza.ID = model.ID; return(pizza); }
/// <summary> /// Map DBPizza => DBPizza /// Sets enum bassed off what pizza class was passed into it. /// </summary> /// <param name="model"></param> /// <returns></returns> public DBPizza Map(APizza model, PizzaDbContext context, bool update = false) { int tempID = model.ID; ASize tempSize = model.Size; switch (model.PIZZA)//if model is a preset pizza, throw everything away and set it to the preset { case PIZZAS.HAWAIIAN: model = new HawaiianPizza(tempSize); break; case PIZZAS.MEAT: model = new MeatPizza(tempSize); break; case PIZZAS.VEGAN: model = new VeganPizza(tempSize); break; case PIZZAS.CUSTOM: break; default: throw new ArgumentException("Pizza not recognized. Pizza could not be mapped properly"); } model.Size = tempSize; model.ID = tempID;//ensure id wasnt lost in the switch case DBPizza dbPizza = context.DBPizzas .Include(pizza => pizza.DBCrust) .Include(pizza => pizza.DBSize) .Include(pizza => pizza.DBPlacedToppings) .ThenInclude(placedTopping => placedTopping.Topping) .FirstOrDefault(pizza => pizza.ID == model.ID) ?? new DBPizza(); if (dbPizza.ID != 0 && !update) { return(dbPizza); } dbPizza.PIZZA = model.PIZZA; dbPizza.DBCrust = mapperCrust.Map(model.Crust, context, update); dbPizza.DBSize = mapperSize.Map(model.Size, context, update); List <DBTopping> mappedToppings = new List <DBTopping>(); model.Toppings.ForEach(topping => mappedToppings.Add(mapperTopping.Map(topping, context, update))); dbPizza.DBPlacedToppings.Clear(); foreach (var group in mappedToppings.GroupBy(topping => topping.TOPPING)) { var firstTopping = group.Last(); if (firstTopping is null) { throw new ArgumentException("Something went wrong!"); } DBPlacedTopping placedTopping = context.DBPlacedToppings .Include(placedTopping => placedTopping.Pizza).Include(placedTopping => placedTopping.Topping) .FirstOrDefault(placedTopping => placedTopping.Pizza.ID == dbPizza.ID && placedTopping.Topping.ID == firstTopping.ID) ?? new DBPlacedTopping(); if (placedTopping.ID != 0 && !update) { continue; } placedTopping.Pizza = dbPizza; placedTopping.Topping = firstTopping; dbPizza.DBPlacedToppings.Add(placedTopping); } model.CalculatePrice(); dbPizza.Price = model.Price; if (dbPizza.ID == 0) { context.DBPizzas.Add(dbPizza); } return(dbPizza); }
public ActionResult <APizza> GetPizzaInfo(PIZZAS PIZZA, SIZES SIZE, CRUSTS CRUST, [FromQuery] List <TOPPINGS> TOPPING) { APizza pizza; ASize size; ACrust crust; List <ATopping> toppings = new List <ATopping>(); switch (SIZE) { case SIZES.SMALL: size = new SmallSize(); break; case SIZES.MEDIUM: size = new MediumSize(); break; case SIZES.LARGE: size = new LargeSize(); break; default: return(StatusCode(400, "Size not recognized")); } switch (CRUST) { case CRUSTS.DEEPDISH: crust = new DeepDishCrust(); break; case CRUSTS.STANDARD: crust = new StandardCrust(); break; case CRUSTS.STUFFED: crust = new StuffedCrust(); break; case CRUSTS.THIN: crust = new ThinCrust(); break; default: return(StatusCode(400, "Crust not recognized")); } foreach (TOPPINGS toppingEnum in TOPPING) { switch (toppingEnum) { case TOPPINGS.BACON: toppings.Add(new Bacon()); break; case TOPPINGS.CHICKEN: toppings.Add(new Chicken()); break; case TOPPINGS.EXTRACHEESE: toppings.Add(new ExtraCheese()); break; case TOPPINGS.GREENPEPPER: toppings.Add(new GreenPepper()); break; case TOPPINGS.HAM: toppings.Add(new Ham()); break; case TOPPINGS.NOCHEESE: toppings.Add(new NoCheese()); break; case TOPPINGS.PINEAPPLE: toppings.Add(new Pineapple()); break; case TOPPINGS.REDPEPPER: toppings.Add(new RedPepper()); break; case TOPPINGS.SAUSAGE: toppings.Add(new Sausage()); break; default: return(StatusCode(400, "Topping not recognized")); } } pizza = new APizza { PIZZA = PIZZA, Name = Enum.GetName <PIZZAS>(PIZZA), Crust = crust, Toppings = toppings }; switch (PIZZA) { case PIZZAS.MEAT: pizza = new MeatPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.HAWAIIAN: pizza = new HawaiianPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.VEGAN: pizza = new VeganPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.CUSTOM: pizza = new CustomPizza(crust, size, toppings); break; default: return(StatusCode(400, "Size not recognized")); } pizza.CalculatePrice(); return(Ok(pizza)); }
public List <APizza> PizzaSeeding() { APizza meat = new MeatPizza(); meat.Crust = new Crust( ) { Name = "thin", Price = 2.50M }; meat.Size = new Size() { Name = "small", Price = 5.00M }; meat.Toppings = new List <Topping>() { new Topping("beef meat", 1.00M), new Topping("cheese", 1.00M) }; APizza vegan = new VeganPizza(); vegan.Crust = new Crust() { Name = "rising", Price = 3.50M }; vegan.Size = new Size() { Name = "small", Price = 5.00M }; vegan.Toppings = new List <Topping> { new Topping("broccoli", 1.00M), new Topping("cheese", 1.00M) }; APizza hawaian = new HawaianPizza(); meat.Crust = new Crust( ) { Name = "thin", Price = 2.50M }; meat.Size = new Size() { Name = "small", Price = 5.00M }; meat.Toppings = new List <Topping>() { new Topping("Ham", 1.00M), new Topping("Pineapple", 0.25M), new Topping("Cheese", 0.50M) }; List <APizza> pizzaList = new List <APizza>(); pizzaList.Add(meat); pizzaList.Add(vegan); pizzaList.Add(hawaian); FileStorage bat = new FileStorage(); //this is the file where the XML will store the pizza files bat.WritePizzaToXml(pizzaList); return(bat.ReadPizzaFromXml <APizza> ().ToList()); /* SINGLETON METHOD WORKFLOW */ // public static StoreSingleton GetInstance() // { // if (_storeSingleton == null) // { // _storeSingleton = new StoreSingleton(); // printer // } // return _storeSingleton; // } }
//not done public static APizza MakePizza() { bool done = false; string size = ""; double sizeCost = 0.0; string input; string crustType = ""; double crustCost = 1.0; do { Console.WriteLine("What size pizza do you want?\n1. Small\n2. Medium\n3.Large"); input = Console.ReadLine(); switch (input) { case "1": size = "small"; sizeCost = 5.0; done = true; break; case "2": size = "medium"; sizeCost = 6.0; done = true; break; case "3": size = "large"; sizeCost = 7.0; done = true; break; default: InvalidInput(); break; } } while (!done); done = false; do { Console.WriteLine("What kind of crust do you want?\n1. Garlic and Herb\n2. Cheese Stuffed\n3. Regular"); input = Console.ReadLine(); switch (input) { case "1": crustType = "Garlic and Herb"; done = true; break; case "2": crustType = "Cheese Stuffed"; done = true; break; case "3": crustType = "Regular"; crustCost = 0.0; done = true; break; default: InvalidInput(); break; } } while (!done); done = false; APizza pizza = null; do { Console.WriteLine("What kind of pizza do you want?\n1. Meat Lovers\n2. Vegan Pizza\n3. Veggie Pizza\n4. Build your own pizza"); input = Console.ReadLine(); switch (input) { case "1": pizza = new MeatPizza(crustType, crustCost, size, sizeCost); done = true; break; case "2": pizza = new VeganPizza(crustType, crustCost, size, sizeCost); done = true; break; case "3": pizza = new VeggiePizza(crustType, crustCost, size, sizeCost); done = true; break; case "4": pizza = new CustomPizza(crustType, crustCost, size, sizeCost); done = true; break; default: InvalidInput(); break; } } while (!done); Console.WriteLine("This pizza cost: $" + pizza.GetPizzaCost()); return(pizza); }
public static void PizzaSeeding() //method { APizza meat = new MeatPizza(); meat.Crust = new Crust( ) { Name = "thin", Price = 2.50M }; meat.Size = new Size() { Name = "small", Price = 5.00M }; meat.Toppings = new List <Topping>() { new Topping("beef meat", 1.00M), new Topping("cheese", 1.00M) }; APizza vegan = new VeganPizza(); vegan.Crust = new Crust() { Name = "rising", Price = 3.50M }; vegan.Size = new Size() { Name = "small", Price = 5.00M }; vegan.Toppings = new List <Topping> { new Topping("broccoli", 1.00M), new Topping("cheese", 1.00M) }; APizza hawaian = new HawaianPizza(); hawaian.Crust = new Crust( ) { Name = "thin", Price = 2.50M }; hawaian.Size = new Size() { Name = "small", Price = 5.00M }; hawaian.Toppings = new List <Topping>() { new Topping("Ham", 1.00M), new Topping("Pineapple", 0.25M), new Topping("Cheese", 0.50M) }; List <APizza> d = new List <APizza>(); d.Add(meat); d.Add(hawaian); d.Add(vegan); var dCount = 1; foreach (var display in d) // displaying the pizzas for the customer to chose { System.Console.WriteLine(dCount + ") " + display.Name); dCount++; } System.Console.WriteLine("Please a chose a number: "); var pizzaNum = System.Console.ReadLine(); }