Exemple #1
0
        public CreateBasketResponse CreateBasket(CreateBasketRequest basketRequest)
        {
            CreateBasketResponse response = new CreateBasketResponse();
            Basket   basket   = new Basket();
            Customer customer = _customerRepository.FindBy(basketRequest.CustomerEmail);

            customer.Email = basketRequest.CustomerEmail;

            basket.SetDeliveryOption(GetCheapestDeliveryOption());
            AddProductsToBasket(basketRequest.ProductsToAdd, basket);
            basket.SetCustomer(customer);
            basket.ThrowExceptionIfInvalid();
            _basketRepository.Save(basket);
            customer.AddBasket(basket);
            customer.ThrowExceptionIfInvalid();
            _customerRepository.Save(customer);
            _uow.Commit();

            response.Basket = _mapper.Map <Basket, BasketView>(basket);

            return(response);
        }