I'm extending (not sure if it's the right word here) a partial Cart class that got generated in Linq to SQL database model.
The business logic is that there can be only one Cart per customer. If a customer doesn't have a cart, it should be created; if a customer has a cart, it should be returned.
Here's what I'm doing:
public partial class Cart
{
//the rest of the Cart class is in the .dbml file created by L2S
public Cart(int userId)
{
Cart c = GetCurrentCart(userId);
this.CartId = c.CartId ;
this.UserId = c.UserId;
}
public Cart GetCurrentCart(int userId)
{
Cart currentCart = new Cart();
// if cart exists - get it from DB
//if not - create it, save in DB, and get if right out
//all of this is done with Linq to SQL
return currentCart;
}
}
calling a method from a constructor just doesn't seem right, am I enforcing the BL the right way?