Пример #1
0
        public async Task OnGet()
        {
            var currUser = _userManager.GetUserId(User);

            ShoppingCart = await LoadCart(currUser);

            CartItems = new GetCartItems(_context).Do(ShoppingCart.CartId);
            Products  = new GetAllProducts(_context).Do()
                        .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                               .Contains(prod.ProductId));
            Categ = new GetAllCategories(_context).Do();
            Order = new GetOrder(_context).Do(currUser, "Pending");
            if (Order == null)
            {
                await new CreateOrder(_context).Do(new OrderViewModel
                {
                    Status       = "Pending",
                    CustomerId   = currUser,
                    TotalOrdered = ShoppingCart.TotalInCart,
                });
                Order = new GetOrder(_context).Do(currUser, "Pending");
            }
            OrderInfos = new GetOrderInfo(_context).Do(Order.OrderId);
            if (OrderInfos == null)
            {
                OrderInfos = new OrderInfosViewModel();
            }
        }
        public async Task <IActionResult> OnGet()
        {
            var currUser = _userManager.GetUserId(User);

            ShoppingCart = new GetShoppingCart(_context).Do(currUser);
            CartItems    = new GetCartItems(_context).Do(ShoppingCart.CartId);
            Products     = new GetAllProducts(_context).Do()
                           .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                                  .Contains(prod.ProductId));
            Order = new GetOrder(_context).Do(currUser, "Pending");
            foreach (var cartitem in CartItems.ToList())
            {
                await new CreateProductInOrder(_context).Do(new ProductInOrdersViewModel
                {
                    OrderRefId   = Order.OrderId,
                    ProductRefId = cartitem.ProductRefId,
                    UsedQuantity = cartitem.Quantity,
                });
                await new UpdateProduct(_context, _fileManager).UpdateStockAfterOrder(cartitem.ProductRefId, cartitem.Quantity);
            }
            Order.Status       = "Ordered";
            Order.TotalOrdered = ShoppingCart.TotalInCart;
            await new UpdateOrder(_context).Do(Order);
            ShoppingCart.Status = "Closed";
            await new UpdateShoppingCart(_context).Do(ShoppingCart);
            return(RedirectToPage("/Account/Manage/Orders", new { Area = "Identity" }));
        }
Пример #3
0
        public async Task <IActionResult> PlaceOrder([FromForm] OrderViewModel vm)
        {
            if (ModelState.IsValid)
            {
                await new UpdateOrder(_context).Do(vm);
                var ShoppingCart = new GetShoppingCart(_context).Do(vm.CustomerId);
                var CartItems    = new GetCartItems(_context).Do(ShoppingCart.CartId);
                var Products     = new GetAllProducts(_context).Do(ShoppingCart.CartId, 0)
                                   .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                                          .Contains(prod.ProductId));

                foreach (var cartitem in CartItems.ToList())
                {
                    await new CreateProductInOrder(_context).Do(new ProductInOrdersViewModel
                    {
                        OrderRefId   = vm.OrderId,
                        ProductRefId = cartitem.ProductRefId,
                        UsedQuantity = cartitem.Quantity,
                    });
                    await new UpdateProduct(_context, _fileManager).UpdateStockAfterOrder(cartitem.ProductRefId, cartitem.Quantity);
                }
                ShoppingCart.Status = "Closed";
                await new UpdateShoppingCart(_context).Do(ShoppingCart);
                return(Ok());
            }
            return(BadRequest());
        }
        public void OnGet()
        {
            var currUser = _userManager.GetUserId(User);

            ShoppingCart = new GetShoppingCart(_context).Do(currUser);
            CartItems    = new GetCartItems(_context).Do(ShoppingCart.CartId);
            Products     = new GetAllProducts(_context).Do()
                           .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId)
                                  .Contains(prod.ProductId));
            Categ      = new GetAllCategories(_context).Do();
            Order      = new GetOrder(_context).Do(currUser, "Pending");
            OrderInfos = new GetOrderInfo(_context).Do(Order.OrderId);
        }