예제 #1
0
        public async Task <ActionResult <BasketDto> > Post([FromBody] CreateBasketModel basketForCreation)
        {
            var basket = new Basket
            {
                UserId = basketForCreation.UserId,
            };
            await _basketRepository.AddBasketAsync(basket);

            return(Ok(new BasketDto
            {
                BasketId = basket.BasketId,
                UserId = basket.UserId
            }));
        }
예제 #2
0
        public async Task <ActionResult <CustomerBasket> > AddItem(string customerId, [FromBody] BasketItem input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var basket = await _repository.AddBasketAsync(customerId, input);

                await this._connection
                .InvokeAsync("UpdateUserBasketCount", $"{customerId}", basket.Items.Count);

                return(Ok(basket));
            }
            catch (KeyNotFoundException)
            {
                return(NotFound(customerId));
            }
        }
        public async Task <IActionResult> Index(string code = null)
        {
            string customerId = userManager.GetUserId(this.User);

            CustomerBasket basket;

            if (!string.IsNullOrWhiteSpace(code))
            {
                var product = await productRepository.GetProductAsync(code);

                if (product == null)
                {
                    return(RedirectToAction("ProductNotFound", "Basket", code));
                }

                var item = new BasketItem(product.Code, product.Code, product.Name, product.Price, 1);
                basket = await basketRepository.AddBasketAsync(customerId, item);
            }
            else
            {
                basket = await basketRepository.GetBasketAsync(customerId);
            }
            return(View(basket));
        }