My Cart class how to automap?

8 views
Skip to first unread message

rat...@gmail.com

unread,
May 4, 2019, 3:15:11 PM5/4/19
to Fluent NHibernate
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; }
   
}
}

Reply all
Reply to author
Forward
0 new messages