///<inheritdoc/>
        public ShoppingCart GetShoppingCartByUserId(Guid id)
        {
            ICustomerRepository customerRepository = SystemObjectFactory.GetInstance <ICustomerRepository>();
            Customer            customer           = customerRepository.GetById(id);

            return(GetById(customer.ShoppingCartId));
        }
        ///<inheritdoc/>
        public void Handle(GetShoppingCartCommand command)
        {
            IShoppingCartRepository repository = SystemObjectFactory.GetInstance <IShoppingCartRepository>();
            ShoppingCart            result     = repository.GetShoppingCartByUserId(command.UserId);

            command.SetResult(result);
        }
        ///<inheritdoc/>
        public ShoppingCart RemoveItem(Guid productId, int quantity, ShoppingCart basket)
        {
            entities.Remove(basket);
            IProductRepository productRepository = SystemObjectFactory.GetInstance <IProductRepository>();
            Product            product           = productRepository.GetById(productId);

            if (product == null)
            {
                return(basket);
            }

            if (basket.Products.ContainsKey(product))
            {
                basket.Products[product] -= quantity;

                if (basket.Products[product] <= 0)
                {
                    basket.Products.Remove(product);
                }
                CommitChanges();
            }
            entities.Add(basket);

            return(basket);
        }
        ///<inheritdoc/>
        public void Handle(AddItemToShoppingCartCommand command)
        {
            IShoppingCartRepository repository = SystemObjectFactory.GetInstance <IShoppingCartRepository>();
            ShoppingCart            basket;

            if (command.ShoppingCartId != null && command.ShoppingCartId != Guid.Empty)
            {
                basket = repository.GetById(command.ShoppingCartId.Value);
            }
            else
            {
                basket = repository.GetShoppingCartByUserId(command.UserId.Value);
            }

            ShoppingCart result = repository.AddItem(command.ProductId, command.Quantity, basket);

            command.SetResult(result);
        }