Пример #1
0
        public IActionResult Checkout(CheckoutCommand command)
        {
            var userIdentifier = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            service.PlaceOrder(command, userIdentifier);
            return(Ok());
        }
Пример #2
0
        public void PlaceOrder(CheckoutCommand command, string userIdentifier)
        {
            var order = Domain.Order.FromCheckout(command, userIdentifier);

            var cart = dbContext
                       .ShoppingCart
                       .Include(x => x.Items)
                       .SingleOrDefault(x => x.SessionId == command.SessionId);

            foreach (var item in cart.Items)
            {
                var product = dbContext.Products.SingleOrDefault(x => x.Id == item.ProductId);
                order.AddItem(product, item.Quantity);
            }

            ChargeCustomer(command.PaymentToken, order.GetTotal(), "Order for " + command.Customer.Email);

            dbContext.Orders.Add(order);

            cart.Empty();

            dbContext.SaveChanges();
        }