private void AddOrderToView(PizzaOrder order)
        {
            Dispatcher.InvokeAsync(() =>
                {
                    var orderViewModel = OrderItem.ConvertOrderToViewModel(order);

                    this.ViewModel.Orders.Add(orderViewModel);
                });
        }
        PizzaOrder CreateRandomOrder()
        {
            // create a new guid to remember this client by
            var clientId = Guid.NewGuid();

            // attach this client id to this order
            var randomOrder = new PizzaOrder
            {
                ClientIdentifier = clientId,
                OrderedTimeStamp = DateTime.Now,
                IsOrdered = false,
                IsReceivedByStore = false
            };

            var toppings = _dbContext.AvailableIngredients.ToList();

            var randomPizzaCount = new Random(Guid.NewGuid().GetHashCode()).Next(1, 5);

            for (int i = 0; i < randomPizzaCount; i++)
            {
                var p = new Pizza
                {
                    Order = randomOrder
                };

                var randomSectionCount = new Random(Guid.NewGuid().GetHashCode()).Next(1, 3);

                for (int x = 0; x < randomSectionCount; x++)
                {
                    var section = new Section
                    {
                        Pizza = p
                    };

                    for (int y = 0; y < randomSectionCount; y++)
                    {
                        var randomToppingCount = new Random(Guid.NewGuid().GetHashCode()).Next(0, toppings.Count() - 1);
                        var topping = toppings[randomToppingCount];

                        section.Ingredients.Add(new IngredientSelection
                        {
                            Section = section,
                            AvailableIngredientId = topping.Id
                        });
                    }
                    p.Sections.Add(section);
                }

                randomOrder.Pizzas.Add(p);
            }

            return randomOrder;
        }
        private void AddOrderToView(PizzaOrder order)
        {
            Dispatcher.InvokeAsync(() =>
                {
                    var orderViewModel = OrderItem.ConvertOrderToViewModel(order,
                        this.ViewModel.Ingredients);

                    this.ViewModel.Orders.Add(orderViewModel);

                    SendOrderStatus(orderViewModel, "Your order has been received by our store.");
                });
        }
        public static OrderItem ConvertOrderToViewModel(PizzaOrder order)
        {
            // get the ingredients from the database
            var dataContext = new EnterprisePizzaDataContext();
            var ingredients = dataContext.AvailableIngredients.ToList();

            // build the object we'll throw into the service bus topic
            var item = new OrderItem
            {
                OrderId = order.Id,
                ClientIdentifier = order.ClientIdentifier.Value
            };

            // add the pizzas to the order
            order.Pizzas.ForEach(p =>
            {
                var pizzaItem = new PizzaItem
                {
                    PizzaId = p.Id
                };

                // add the sections to the pizza
                p.Sections.ForEach(s =>
                {
                    var sectionItem = new SectionItem();

                    s.Ingredients.ForEach(i =>
                    {
                        sectionItem.Toppings.Add(
                            ingredients.First(x =>
                                x.Id == i.AvailableIngredientId).Name);
                    });

                    pizzaItem.Sections.Add(sectionItem);
                });

                item.Pizzas.Add(pizzaItem);
            });

            return item;
        }
        public static OrderItem ConvertOrderToViewModel(PizzaOrder order, 
            IEnumerable<IngredientAvailability> ingredients)
        {
            // build the object we'll throw into the service bus topic
            var item = new OrderItem
            {
                OrderId = order.Id,
                ClientIdentifier = order.ClientIdentifier.Value
            };

            // add the pizzas to the order
            order.Pizzas.ForEach(p =>
            {
                var pizzaItem = new PizzaItem
                {
                    PizzaId = p.Id
                };

                // add the sections to the pizza
                p.Sections.ForEach(s =>
                {
                    var sectionItem = new SectionItem();

                    s.Ingredients.ForEach(i =>
                    {
                        sectionItem.Toppings.Add(
                            ingredients.First(x =>
                                x.Id == i.AvailableIngredientId).Name);
                    });

                    pizzaItem.Sections.Add(sectionItem);
                });

                item.Pizzas.Add(pizzaItem);
            });

            return item;
        }