public Cart MapIt(Cart cart, LineItem line)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (cart == null)
                return current;

            // Is this the same cart as the current one we're processing
            if (current != null && current.Id == cart.Id)
            {
                // Yes, just add this lines to the current cart's collection of lines
                current.Lines.Add(line);

                // Return null to indicate we're not done with this cart yet
                return null;
            }

            // This is a different cart to the current one, or this is the
            // first time through and we don't have a cart yet

            // Save the current cart
            var prev = current;

            // Setup the new current cart
            current = cart;
            current.Lines = new List<LineItem>();
            if (line != null)
              current.Lines.Add(line);

            // Return the now populated previous cart (or null if first time through)
            return prev;
        }
 public Cart GetActiveCart()
 {
     var cart = _shoppingCartRepository.GetActiveCart();
     if (cart == null)
     {
         var newCart = new Cart();
         return _shoppingCartRepository.Add(newCart);
     }
     return cart;
 }
 public void AddItem(Cart cart, Product product, int quantity)
 {
     var existingLine = cart.Lines.SingleOrDefault(x => x.ProductId == product.Id);
     if (existingLine != null)
     {
         _shoppingCartRepository.UpdateQuantity(cart, product, quantity);
     }
     else
     {
         _shoppingCartRepository.AddItem(cart, product, quantity);
     }
 }
 public void Checkout(Cart cart)
 {
     cart.IsOrder = true;
     _shoppingCartRepository.Update(cart);
 }