Exemplo n.º 1
0
        // Working on this
        public async Task <bool> ProcessOrderAsync(decimal total, string stripeToken, BillingDetail billingDetail, List <CartItem> cartItems, AppUser user)
        {
            // Process payment - Stripe
            string clientSecret = CreateStripePaymentIntent(total);

            // if charge succeeded
            if (true)
            {
                var order = new Order
                {
                    Total         = total,
                    Placed        = DateTime.UtcNow,
                    BillingDetail = billingDetail,
                    User          = user,
                    //StripeChargeId = charge.Id
                };

                var orderDetails = cartItems.Select(item => new OrderDetail
                {
                    ProductId       = item.ProductId,
                    ProductName     = item.Name,
                    ProductQuantity = item.Quantity,
                    ProductCost     = item.Price.Cost,
                    Order           = order
                }).ToList();

                (bool success, int orderId) = await AddOrderAsync(order, orderDetails);

                return(success);
            }
        }
Exemplo n.º 2
0
        public async Task <(bool, int)> CreateOrderAsync(List <CartItem> cartItems, AppUser user)
        {
            var order = new Order
            {
                Placed = DateTime.UtcNow,
                User   = user
            };

            var orderDetails = cartItems.Select(item => new OrderDetail
            {
                ProductId       = item.ProductId,
                ProductName     = item.Name,
                ProductQuantity = item.Quantity,
                ProductCost     = item.Price.Cost,
                Order           = order
            }).ToList();

            (bool success, int orderId) = await AddOrderAsync(order, orderDetails);

            return(success, orderId);
        }
Exemplo n.º 3
0
        public async Task <(bool, int)> AddOrderAsync(Order order, IEnumerable <OrderDetail> orderDetails)
        {
            if (order == null)
            {
                return(false, 0);
            }

            try
            {
                await _database.OrderDetails.AddRangeAsync(orderDetails);

                await _database.Orders.AddAsync(order);

                await _database.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false, 0);
            }

            return(true, order.OrderId);
        }