Exemplo n.º 1
0
        public async Task <IActionResult> OnPost(
            [FromServices] AddToCart addToCart)
        {
            var stockAdded = await addToCart.DoAsync(CartViewModel);

            if (stockAdded)
            {
                return(RedirectToPage("Cart"));
            }
            else
            {
                // TODO: add a warning
                return(RedirectToPage("Error"));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync([FromServices] AddToCart addToCart)
        {
            //ToDo: check whether any stock was selected
            var stockAddedToCart = await addToCart.DoAsync(CartViewModel);

            if (stockAddedToCart)
            {
                return(RedirectToPage("Cart"));
            }
            else
            {
                //ToDo: Redirect to warning
                return(Page());
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddOneAsync(int id, [FromServices] AddToCart addToCart)
        {
            var success = await addToCart.DoAsync(new AddToCart.Request()
            {
                StockId = id,
                Qty     = 1,
            });


            if (success)
            {
                return(Ok("Item was added successfully."));
            }

            return(BadRequest("Failed to add to the cart."));
        }
Exemplo n.º 4
0
        public async Task <bool> AddOneAsync(int productId)
        {
            var request = new AddToCart.Request
            {
                ProductId = productId,
                Quantity  = 1
            };

            var success = await _addToCart.DoAsync(request);

            if (success)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPost([FromServices] AddToCart addToCart, int id)
        {
            var stockAdded = await addToCart.DoAsync(new AddToCart.Request
            {
                ProductId = id,
                Quantity  = 1
            });

            if (stockAdded)
            {
                return(RedirectToPage("Cart"));
            }
            else
            {
                return(Page());
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> AddOne(
            Guid stockId,
            [FromServices] AddToCart addToCart)
        {
            var request = new AddToCart.Request {
                StockId  = stockId,
                Quantity = 1
            };

            var success = await addToCart.DoAsync(request);

            if (success)
            {
                return(Ok("Item added to cart"));
            }
            return(BadRequest("Failed to add to cart"));
        }