My Cart Class

 public virtual int CartId { get; set; }
        public
        List<CartLine> _cartLines = new List<CartLine>();
        public void AddToCart(Product product, int quantity)
        {
            CartLine cartLine = _cartLines.FirstOrDefault(c => 
            c.Product.ProductId == product.ProductId);
            if (cartLine == null)
            {
                _cartLines.Add(new CartLine { Product = product, Qunatity = 
quantity });
            }
            else
            {
                cartLine.Qunatity += quantity;
            }
        }
        public void RemoveFromCart(Product product)
        {
            _cartLines.RemoveAll(p => p.Product.ProductId == product.ProductId);
        }

        public decimal Total
        {
            get
            {
                return _cartLines.Sum(c => c.Product.UnitPrice * c.Qunatity);
            }
        }
        public void Clear()
        {
            _cartLines.Clear();
        }
        public List<CartLine> Lines
        {
            get
            {
                return _cartLines;
            }
        }
    }

    public class CartLine
    {
        public Product Product { get; set; }
        public int Qunatity { get; set; }
    }
}


-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at https://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.

Reply via email to