public async Task <ActionResult> AddItemToBasket(AddItemToBasketDTO dto)
        {
            var basketId = GetBasketId();
            var command  = _mapper.Map <AddItemToBasketCommand>(dto);

            command.BasketId = basketId;

            var basketDto = await _mediator.Send(command);

            if (basketId == null)
            {
                CreateBasketCookie(basketDto.Id);
            }

            return(CreatedAtAction(nameof(Get), basketDto));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> AddItemToBasket(AddItemToBasketDTO dto)
        {
            var basketId = GetBasketId();

            using var uow = _unitOfWorkFactory.Create();

            var basket = await _basketService.AddItemToBasketAsync(basketId, dto.ProductId, dto.Quantity);

            uow.Commit();

            if (basketId == null)
            {
                CreateBasketCookie(basket.Id);
            }

            var basketDTO = _mapper.Map <BasketDTO>(basket);

            return(CreatedAtAction(nameof(Get), basketDTO));
        }