Ejemplo n.º 1
0
        // Function to get individual price
        //using toppings first then accounting for size
        public async Task <decimal> getPizzaPriceAsync(int givenPizzaId)
        {
            decimal totalPrice = 0m;
            var     toppings   = PizzaToppings.Where(n => n.pizzaId == givenPizzaId);

            foreach (PizzaTopping topping in toppings)
            {
                // Query database and add all topping prices to pizza
                var toppingObject = await Toppings.FirstOrDefaultAsync(n => n.id == topping.toppingId);

                totalPrice += toppingObject.price;
            }
            var ourPizza = await Pizza.SingleOrDefaultAsync(n => n.id == givenPizzaId);

            switch (ourPizza.size)
            {
            case "small":
                totalPrice += 8.00m;
                break;

            case "medium":
                totalPrice += 12.00m;
                break;

            case "large":
                totalPrice += 16.00m;
                break;

            case "special":
                totalPrice += 10.00m;
                break;

            default:
                break;
            }
            return(totalPrice);
        }