Exemplo n.º 1
0
        public async Task <Order> Create(CreateOrderModel createOrderModel)
        {
            var order = new Order
            {
                CustomerId   = createOrderModel.CustomerId,
                Country      = createOrderModel.Country,
                RestaurantId = createOrderModel.RestaurantId,
                OrderLines   = createOrderModel.OrderLines.Select(x => new OrderLine()
                {
                    Quantity = x.Quantity,
                    Meal     = new Meal()
                    {
                        Name      = x.Meal.Name,
                        MealItems = x.Meal.MealItems.Select(m => new MealItem()
                        {
                            Name = m.Name
                        }),
                        ExtraMealItems = x.Meal.ExtraMealItems.Select(em => new ExtraMealItem()
                        {
                            Name = em.Name, Quantity = em.Quantity
                        })
                    }
                }),
                OrderStatus = OrderStatus.Created
            };
            // Right now we just insert and message our payment api, and then we return the order
            //
            // To make it simple, we should all this logic, messaging etc, and whenever the order is
            // accepted/rejected by the res, return the order and make the client wait.
            await _orders.InsertOneAsync(order);

            await _publisher.AuthorizePaymentForOrder(order);

            return(order);
        }