示例#1
0
        public async Task <IActionResult> OnPost([FromServices] AddToCart addToCart)
        {
            var stockAdded = await addToCart.Action(CartViewModel);

            if (stockAdded)
            {
                return(RedirectToPage("/Cart"));
            }
            else
            {
                //TODO 1 Add warning that stock unavailable
                return(Page());
            }
        }
示例#2
0
        public async Task <IActionResult> AddOne(int stockId, int qty, [FromServices] AddToCart addToCart)
        {
            var request = new AddToCart.Request
            {
                StockId = stockId,
                Qty     = qty
            };

            var success = await addToCart.Action(request);

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