Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                Basket = BasketHelper.GetBasket(HttpContext.Session);
                Fail   = true;
                return(Page());
            }
            Basket = BasketHelper.GetBasket(HttpContext.Session);
            var   userId   = _um.GetUserId(User);
            Order newOrder = _ds.CreateOrderFromBasket(Basket, userId, Shipping.Value, Payment.Value);
            var   orderId  = _ds.SaveOrder(newOrder);

            foreach (var item in Basket.Items)
            {
                await _ds.DecreaseProductStockAsync(item.ProductId, item.Quantity);
            }
            BasketHelper.ClearBasket(HttpContext.Session);
            return(RedirectToPage("./CheckoutConfirm", new { orderid = orderId }));
        }