public CreateBasketResponse CreateBasket(CreateBasketRequest request)
        {
            CreateBasketResponse response = new CreateBasketResponse();

            Basket basket = new Basket();

            basket.SetDeliveryOption(GetCheapestDeliveryOption());

            AddProductsToBasket(request.ProductsToAdd, basket);

            ThrowExceptionIfBasketIsInvalid(basket);

            _basketRepository.Save(basket);
            _uow.Commit();

            response.Basket = basket.ConvertToBasketView();

            return response;
        }
        public JsonResult AddToBasket(int productId)
        {
            BasketSummaryView basketSummaryView = new BasketSummaryView();
            Guid basketId = base.GetBasketId();
            bool createNewBasket = basketId == Guid.Empty;

            if (createNewBasket == false)
            {
                ModifyBasketRequest modifyBasketRequest =
                                       new ModifyBasketRequest();

                modifyBasketRequest.ProductsToAdd.Add(productId);
                modifyBasketRequest.BasketId = basketId;

                try
                {
                    ModifyBasketResponse response = _basketService
                                                      .ModifyBasket(modifyBasketRequest);
                    basketSummaryView = response.Basket.ConvertToSummary();
                    SaveBasketSummaryToCookie(basketSummaryView.NumberOfItems,
                                              basketSummaryView.BasketTotal);
                }
                catch (BasketDoesNotExistException ex)
                {
                    createNewBasket = true;
                }
            }

            if (createNewBasket)
            {
                CreateBasketRequest createBasketRequest =
                                         new CreateBasketRequest();

                createBasketRequest.ProductsToAdd.Add(productId);

                CreateBasketResponse response = _basketService
                                                   .CreateBasket(createBasketRequest);

                SaveBasketIdToCookie(response.Basket.Id);
                basketSummaryView = response.Basket.ConvertToSummary();
                SaveBasketSummaryToCookie(basketSummaryView.NumberOfItems,
                                          basketSummaryView.BasketTotal);
            }

            return Json(basketSummaryView);
        }