示例#1
0
        public async Task CreateOrder(Order order)
        {
            _orderRepo.CreatOrder(order);
            await _orderRepo.Add(order);

            await _orderRepo.SaveAsync();

            var shoppingCartItems = _shoppingCartRepo.GetShoppingCartItems();

            foreach (var shoppingCartItem in shoppingCartItems)
            {
                var orderDetail = new OrderDetail
                {
                    Amount  = shoppingCartItem.Amount,
                    Price   = shoppingCartItem.Candy.Price,
                    CandyId = shoppingCartItem.Candy.CandyId,
                    OrderId = order.OrderId
                };
                await _orderDetailRepo.Add(orderDetail);
            }

            await _orderDetailRepo.SaveAsync();
        }