Exemple #1
0
        public async Task CreateBasket()
        {
            var basketId = await _storage.InitBasketAsync();

            Assert.GreaterOrEqual(0, basketId);

            var basket = await _storage.GetBasketAsync(basketId);

            Assert.NotNull(basket);
            Assert.AreEqual(0, basket.Items.Count);

            var item = new Item {
                Id = 1
            };
            await _storage.AddOrUpdateItemAsync(item);

            basket.Items.Add(1, new BasketItem {
                Item  = item,
                Count = 1
            });

            await _storage.AddOrReplaceBasketAsync(basket);

            basket = await _storage.GetBasketAsync(basketId);

            Assert.NotNull(basket);
            Assert.AreEqual(1, basket.Items.Count);
        }
Exemple #2
0
        public async Task <ActionResult <BasketResponse> > Post([FromBody] BasketResponse basket)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (basket == null)
            {
                return(BadRequest());
            }

            if (await _storage.BasketExistsAsync(basket.Id))
            {
                return(BadRequest("Basket already exists"));
            }

            if (!await _storage.AddOrReplaceBasketAsync(_mapper.Map <Basket>(basket)))
            {
                return(BadRequest("One of items does not exist or is incorrect."));
            }

            return(Ok(basket));
        }