Exemplo n.º 1
0
        public async Task <IActionResult> Index(OrderViewModel orderViewModel)
        {
            if (ModelState.IsValid)
            {
                var items = await _shoppingCartService.GetShoppingCartItems(Session.ShoppingCartId);

                var customer = await _customerService.AddCustomerAsync(_mapper.Map <Customer>(orderViewModel));

                var order = new Order()
                {
                    Amount     = _shoppingCartService.GetShoppingCartTotal(Session.ShoppingCartId),
                    CustomerId = customer.Id,
                    Date       = DateTime.Now
                };
                await _orderService.AddOrderAsync(order);

                foreach (var item in items)
                {
                    var orderItem = new OrderItem()
                    {
                        OrderId            = order.Id,
                        ProductItemId      = item.ProductItemId,
                        ComboMealId        = item.ComboMealId,
                        CustomizeProductId = null,
                        Quantity           = item.Quantity
                    };
                    await _orderItemService.AddOrderItemAsync(orderItem);
                }

                await _shoppingCartService.ClearCart(Session.ShoppingCartId);

                return(RedirectToAction("OrderComplete"));
            }
            return(View(orderViewModel));
        }
 public async Task <ActionResult <int> > Post([FromBody] OrderItemModel orderItemModel)
 {
     return(Ok(await _OrderItemServiceService.AddOrderItemAsync(orderItemModel)));
 }