Esempio n. 1
0
        public async Task <IActionResult> AddItemToBasket(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var itemId   = req.Form["itemid"].ToString();
            var basketId = req.Form["basketId"].ToString();

            if (string.IsNullOrEmpty(basketId))
            {
                var newBasketId = await CreateBasketWithItem(itemId);

                return(new OkObjectResult(newBasketId));
            }
            else if (!string.IsNullOrEmpty(basketId) && !await _basketRepo.BasketExist(basketId))
            {
                var newBasketId = await CreateBasketWithItem(itemId);

                return(new OkObjectResult(newBasketId));
            }
            else
            {
                await AddItemToBasket(itemId, basketId);

                return(new OkResult());
            }
        }