public Entities.Crust Map(Domain.Models.Crust model, Entities.AnimalsDbContext context) { Entities.CRUST_TYPE crustType; switch (model) { case CheeseStuffedCrust: crustType = Entities.CRUST_TYPE.CheeseStuffed; break; case DeepDishCrust: crustType = Entities.CRUST_TYPE.DeepDish; break; case TraditionalCrust: crustType = Entities.CRUST_TYPE.Traditional; break; default: throw new ArgumentException("CrustMapper ran into an unknown type of crust when mapping from Domain Model to DB Model"); } var dbCrust = context.Crusts.FirstOrDefault(c => c.CrustType == crustType); if (dbCrust is not null) { return(dbCrust); } Entities.Crust crust = new Entities.Crust(); crust.CrustType = crustType; crust.Price = model.Price; return(crust); }
public Entities.Size Map(Domain.Models.Size model, Entities.AnimalsDbContext context) { Entities.SIZE_TYPE sizeType; switch (model) { case Domain.Models.SmallSize: sizeType = Entities.SIZE_TYPE.Small; break; case Domain.Models.MediumSize: sizeType = Entities.SIZE_TYPE.Medium; break; case Domain.Models.LargeSize: sizeType = Entities.SIZE_TYPE.Large; break; default: throw new ArgumentException("SizeMapper encountered an unknown type when mapping from Domain Model to DB Model"); } var dbSize = context.Sizes.FirstOrDefault(s => s.SizeType == sizeType); if (dbSize is not null) { return(dbSize); } Entities.Size size = new Entities.Size(); size.SizeType = sizeType; size.Price = model.Price; return(size); }
public Store Map(AStore model, Entities.AnimalsDbContext context) { if (model.ID != -1) { var dbStore = context.Stores.FirstOrDefault(s => s.ID == model.ID); if (dbStore is not null) { return(dbStore); } } STORE_TYPE storeType; switch (model) { case ChicagoStore: storeType = STORE_TYPE.Chicago; break; case NewYorkStore: storeType = STORE_TYPE.NewYork; break; default: throw new ArgumentException("Store mapper is attempting to map a store instance that does not exist in the database"); } Store store = new Store(); store.Name = model.Name; store.StoreType = storeType; return(store); }
public Pizza Map(APizza model, Entities.AnimalsDbContext context) { PIZZA_TYPE pizzaType; switch (model) { case MeatPizza: pizzaType = PIZZA_TYPE.Meat; break; case VeganPizza: pizzaType = PIZZA_TYPE.Vegan; break; case CustomPizza: pizzaType = PIZZA_TYPE.Custom; break; default: throw new ArgumentException("PizzaMapper encountered unknown type when mapping from Domain Model to DB Model"); } Pizza pizza = new Pizza(); pizza.PizzaType = pizzaType; pizza.Crust = crustMapper.Map(model.Crust, context); pizza.Size = sizeMapper.Map(model.Size, context); // need to group the PizzaToppings by their topping's toppingtype // need to make AMOUNT = Count of the grouping List <Entities.Topping> mappedToppings = new List <Entities.Topping>(); model.Toppings.ForEach(t => mappedToppings.Add(toppingMapper.Map(t, context))); var grouped = mappedToppings.GroupBy(t => t.ToppingType); foreach (var group in mappedToppings.GroupBy(t => t.ToppingType)) { var firstTopping = group.First(); if (firstTopping is null) { // Should never happen throw new ArgumentException("Everything is on fire. Just rewrite everything please"); } PizzaTopping pt = new PizzaTopping(); pt.Pizza = pizza; pt.Topping = firstTopping; pt.Amount = group.Count(); firstTopping.PizzaToppings.Add(pt); pizza.PizzaToppings.Add(pt); } pizza.Price = model.Price; return(pizza); }
public Entities.Customer Map(Domain.Models.Customer model, Entities.AnimalsDbContext context) { var dbCustomer = context.Customers.FirstOrDefault(c => c.Name.Equals(model.Name)); if (dbCustomer is not null) { return(dbCustomer); } Entities.Customer customer = new Entities.Customer(); customer.Name = model.Name; return(customer); }
public Entities.Order Map(Domain.Models.Order model, Entities.AnimalsDbContext context) { Entities.Order order = new Entities.Order(); order.Customer = customerMapper.Map(model.Customer, context); foreach (Domain.Abstracts.APizza pizza in model.Pizzas) { var mappedPizza = pizzaMapper.Map(pizza, context); mappedPizza.Orders.Add(order); order.Pizzas.Add(mappedPizza); } //model.Pizzas.ForEach(p => pizzas.Add(pizzaMapper.Map(p, context))); order.Store = storeMapper.Map(model.Store, context); order.TotalPrice = model.Price; order.TimePlaced = DateTime.Now; return(order); }
public Entities.Topping Map(Domain.Models.Topping model, Entities.AnimalsDbContext context) { Entities.TOPPING_TYPE toppingType; switch (model) { case Domain.Models.BaconTopping: toppingType = Entities.TOPPING_TYPE.Bacon; break; case Domain.Models.MushroomTopping: toppingType = Entities.TOPPING_TYPE.Mushroom; break; case Domain.Models.OnionTopping: toppingType = Entities.TOPPING_TYPE.Onion; break; case Domain.Models.PepperoniTopping: toppingType = Entities.TOPPING_TYPE.Pepperoni; break; default: throw new ArgumentException("ToppingMapper encountered an unknown type when mapping from Domain Model to DB Model"); } var dbTopping = context.Toppings.FirstOrDefault(t => t.ToppingType == toppingType); if (dbTopping is not null) { return(dbTopping); } Entities.Topping topping = new Entities.Topping(); topping.ToppingType = toppingType; topping.Price = model.Price; return(topping); }