using System.Collections.Generic;
using PizzaShop.Persistance;
public static void Main()
var repo = new Repository();
var pizzas = repo.GetProducts();
var crusts = repo.GetCrusts();
var toppings = repo.GetToppings();
var order = new Order() {PizzaSize = (int)PizzaSize.Small,
PizzaCrust = (int) PizzaCrust.Thin,
Sausage =(int)PizzaTopping.Sausage,
Pepperoni = (int)PizzaTopping.Pepperoni,
Onions = (int)PizzaTopping.Onions,
GreenPeppers = (int)PizzaTopping.GreePeppers};
var manager = new PriceManager();
var totalPrice = manager.CalculatePrice(pizzas, crusts, toppings, order);
Console.WriteLine(totalPrice.ToString());
namespace PizzaShop.Persistance
private List<PizzaPie> _productList;
private List<PieCrust> _productCrustList;
private List<Topping> _toppingList;
public IEnumerable<Topping> GetToppings ()
this._toppingList = new List<Topping> {
new Topping {ToppingID = Guid.NewGuid(), ToppingName = "Sausage",
ToppingPrice = 2m, PizzaTopping = 0},
new Topping {ToppingID = Guid.NewGuid(), ToppingName = "Pepperoni",
ToppingPrice = 1.5m, PizzaTopping = 1},
new Topping {ToppingID = Guid.NewGuid(), ToppingName = "Onions",
ToppingPrice = 1m, PizzaTopping = 2},
new Topping {ToppingID = Guid.NewGuid(), ToppingName = "Green Peppers",
ToppingPrice = 1m,PizzaTopping = 3}
return this._toppingList;
public IEnumerable<PizzaPie> GetProducts ()
this._productList = new List<PizzaPie> {
new PizzaPie{ProductID = Guid.NewGuid(), Name = "Small",
ProductSize = 12, ProductPrice = 12m, Size = (int)PizzaSize.Small},
new PizzaPie{ProductID = Guid.NewGuid(), Name = "Medium",
ProductSize = 12, ProductPrice = 14m, Size = (int)PizzaSize.Medium},
new PizzaPie{ProductID = Guid.NewGuid(), Name = "Large",
ProductSize = 12, ProductPrice = 16m, Size = (int)PizzaSize.Large}};
return this._productList;
public IEnumerable<PieCrust> GetCrusts ()
this._productCrustList = new List<PieCrust> {
new PieCrust{ProductCrustID = Guid.NewGuid(),Name = "Regular",
CrustPrice = 0m, PizzaCrust = (int)PizzaCrust.Regular},
new PieCrust{ProductCrustID = Guid.NewGuid(),Name = "Thin",
CrustPrice = 0m, PizzaCrust = (int)PizzaCrust.Thin},
new PieCrust{ProductCrustID = Guid.NewGuid(),Name = "Thick",
CrustPrice = 2m, PizzaCrust = (int)PizzaCrust.Thick}
return this._productCrustList;
namespace PizzaShop.Domain
public static class Extensions
public static decimal WithPieSize(this IEnumerable<PizzaPie> pizzas, int selection)
var result = pizzas.Where(p => p.Size == selection)
.Select(p => p.ProductPrice)
public static decimal WithCrust(this decimal price,IEnumerable<PieCrust> crusts, int selection)
var result = crusts.Where(p => p.PizzaCrust == selection)
.Select(p => p.CrustPrice)
public static decimal WithTopping(this decimal price,IEnumerable<Topping> toppings, int selection)
var result = toppings.Where(p => p.PizzaTopping == selection)
.Select(p => p.ToppingPrice)
public class PriceManager
public decimal CalculatePrice(IEnumerable<PizzaPie> pizzas,IEnumerable<PieCrust> crusts,
IEnumerable<Topping> toppings,Order order)
var result = pizzas.WithPieSize(order.PizzaSize)
.WithCrust(crusts,order.PizzaCrust)
.WithTopping(toppings, order.Sausage)
.WithTopping(toppings, order.Pepperoni)
.WithTopping(toppings, order.Onions)
.WithTopping(toppings, order.GreenPeppers);
public System.Guid ProductID {get;set;}
public string Name {get;set;}
public int ProductSize {get;set;}
public decimal ProductPrice {get;set;}
public int Size {get;set;}
public System.Guid ProductCrustID {get;set;}
public string Name {get;set;}
public decimal CrustPrice {get;set;}
public int PizzaCrust {get;set;}
public System.Guid ToppingID {get;set;}
public string ToppingName {get;set;}
public decimal ToppingPrice {get;set;}
public int PizzaTopping {get;set;}
namespace EntityFramework
public string CustomerID {get;set;}
public string Name {get;set;}
public string Address {get;set;}
public int Zip {get;set;}
public int Phone {get;set;}
public Customer Customer {get; set;}
public int PizzaSize {get;set;}
public int PizzaCrust {get;set;}
public int PaymentType {get;set;}
public int Sausage {get;set;}
public int Pepperoni {get;set;}
public int Onions {get;set;}
public int GreenPeppers {get;set;}
public decimal TotalCost {get;set;}