public OrderVm GetPriceQuote(NewOrderVm order) { OrderVm quote; quote = Domain.Models.Pizza.Methods.Utility.GetPriceQuoteForCustomerOrder(order); var deliveryCost = Domain.Models.Pizza.Methods.Utility.GetDistanceCost(order.Distance); quote.DeliveryCost = (deliveryCost < 0) ? 0 : deliveryCost; return(quote); }
/// <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 }); }
public async Task <OrderVm> CreateOrderAsync(NewOrderVm order) { var newOrder = Domain.Models.Pizza.Methods.Utility.GetPriceQuoteForCustomerOrder(order); var saveOrder = new Order { TotalPizzas = newOrder.TotalPizzas, TotalCost = newOrder.TotalCost }; return(await _pizzaOrderRepository.CreateOrderAsync(saveOrder)); }
public async Task <OrderVm> CreateOrder(NewOrderVm order) { var newOrder = await _pizzaOrderService.CreateOrderAsync(order); return(newOrder); }
public OrderVm GetPriceQuote(NewOrderVm orderVm) { return(_pizzaOrderService.GetPriceQuote(orderVm)); }