public CartDto Add(Guid customerId, CartProductDto productDto)
        {
            CartDto cartDto = null;

            Customer customer = this.customerRepository.FindById(customerId);

            if (customer == null)
            {
                throw new Exception(String.Format("Customer was not found with this Id: {0}", customerId));
            }

            Cart cart = this.cartRepository.FindOne(new CustomerCartSpec(customerId));

            if (cart == null)
            {
                cart = Cart.Create(customer);
                this.cartRepository.Add(cart);
            }

            Product product = this.productRepository.FindById(productDto.ProductId);

            this.validateProduct(product.Id, product);

            //Double Dispatch Pattern
            cart.Add(CartProduct.Create(customer, cart, product,
                                        productDto.Quantity, taxDomainService));

            cartDto = Mapper.Map <Cart, CartDto>(cart);
            this.unitOfWork.Commit();
            return(cartDto);
        }
        public CartDto Add(Guid customerId, CartProductDto productDto)
        {
            CartDto cartDto = null;
            Customer customer = this.repositoryCustomer.FindById(customerId);
            this.validateCustomer(customerId, customer);

            Product product = this.repositoryProduct.FindById(productDto.ProductId);
            this.validateProduct(product.Id, product);

            //Double Dispatch Pattern
            customer.Cart.Add(CartProduct.Create(customer.Cart, product,
                productDto.Quantity, taxDomainService));

            cartDto = Mapper.Map<Cart, CartDto>(customer.Cart);
            this.unitOfWork.Commit();
            return cartDto;
        }
예제 #3
0
        public CartDto Add(Guid customerId, CartProductDto productDto)
        {
            CartDto  cartDto  = null;
            Customer customer = this.repositoryCustomer.FindById(customerId);

            this.validateCustomer(customerId, customer);

            Product product = this.repositoryProduct.FindById(productDto.ProductId);

            this.validateProduct(product.Id, product);

            //Double Dispatch Pattern
            customer.Cart.Add(CartProduct.Create(customer.Cart, product,
                                                 productDto.Quantity, taxDomainService));

            cartDto = Mapper.Map <Cart, CartDto>(customer.Cart);
            this.unitOfWork.Commit();
            return(cartDto);
        }