Hey guys, having a bit of trouble with a customized eCommerce. The part I want to focus on is the adding of an item to the shopping cart (and the details that go along with each item). Everything works as is with the things I need commented...
initial call to add item to my cart model
<a href="/AddToCart.aspx?productID=<%# Eval("ItemID") %>">
<span style="border:1px solid black;padding:2px;">
Add To Cart
</span>
</a>
backend logic (called when addtocart[blank page with backend] loads)
public void AddToCart(int id)
{
// Retrieve the product from the database.
ShoppingCartId = GetCartId();
var cartItem = _db.ShoppingCartItems.SingleOrDefault(
c => c.CartId == ShoppingCartId
&& c.ProductId == id);
if (cartItem == null)
{
// Create a new cart item if no cart item exists.
cartItem = new CartItem
{
ItemId = Guid.NewGuid().ToString(),
ProductId = id,
CartId = ShoppingCartId,
// ProductName = GetName(id),
// ProductPrice = GetPrice(id),
Quantity = 1,
DateCreated = DateTime.Now
};
_db.ShoppingCartItems.Add(cartItem);
}
else
{
// If the item does exist in the cart,
// then add one to the quantity.
cartItem.Quantity++;
}
_db.SaveChanges();
}
CartItem model
public class CartItem
{
[Key]
public string ItemId { get; set; }
public string CartId { get; set; }
public int Quantity { get; set; }
public System.DateTime DateCreated { get; set; }
public int ProductId { get; set; }
//public string ProductName { get; set; }
//public string ProductPrice { get; set; }
public virtual Product Product { get; set; }
}
As it shows currently here, it works. Adds a unique product item to the cart with ID retrieved from the DB, but When I uncomment either the Product name or ProductPrice attributes (and their corresponding functions/etc) I get an inner exception... something along the lines of invalid column name ProductPrice (even if I use hard-typed dummy data).
Let me know if i can clarify at all... any ideas are much appreciated!