public async Task <ActionResult <BasketLineDTO> > Post(Guid basketId,
                                                               [FromBody] BasketLineCreation basketLineCreation)
        {
            if (!await _basketRespository.BasketExists(basketId))
            {
                return(NotFound());
            }

            if (!await _eventRepository.EventExists(basketLineCreation.EventId))
            {
                var eventFromCatalog = await _eventComponentService.GetEvent(basketLineCreation.EventId);

                _eventRepository.AddEvent(eventFromCatalog);
                await _eventRepository.SaveChanges();
            }

            var basketLineEntity = _mapper.Map <Entities.BasketLine>(basketLineCreation);

            var processedBasketLine = await _basketLineRepository.AddOrUpdateBasketLine(basketId, basketLineEntity);

            await _basketLineRepository.SaveChanges();

            var basketLineToReturn = _mapper.Map <BasketLineDTO>(processedBasketLine);

            return(CreatedAtRoute(
                       "GetBasketLine",
                       new { basketId = basketLineEntity.BasketId, basketLineId = basketLineEntity.BasketLineId },
                       basketLineToReturn));
        }
        public async Task <IActionResult> AddLine(BasketLineCreation basketLine)
        {
            var basketId = Request.Cookies.GetCurrentBasketId(settings);
            var newLine  = await basketService.AddToBasket(basketId, basketLine);

            Response.Cookies.Append(settings.BasketIdCookieName, newLine.BasketId.ToString());

            return(RedirectToAction("Index"));
        }
        public async Task <BasketLine> AddToBasket(Guid basketId, BasketLineCreation basketLine)
        {
            if (basketId == Guid.Empty)
            {
                var basketResponse = await client.PostAsJson("/api/baskets", new BasketCreation { UserId = settings.UserId });

                var basket = await basketResponse.ReadContentAs <Basket>();

                basketId = basket.BasketId;
            }

            var response = await client.PostAsJson($"api/baskets/{basketId}/basketlines", basketLine);

            return(await response.ReadContentAs <BasketLine>());
        }