本文整理汇总了C#中Cart类的典型用法代码示例。如果您正苦于以下问题:C#Cart类的具体用法?C#Cart怎么用?C#Cart使用的例子?这里精选的类代码示例或许可以为您提供帮助。
示例1:btnAddToCart_Click
protectedvoidbtnAddToCart_Click(objectsender,EventArgse)
{
Cartcart;
if(Session["Cart"]isCart)
cart=Session["Cart"]asCart;
else
cart=newCart();
shortquantity=1;
try
{
quantity=Convert.ToInt16(txtQuantity.Text);
}
catch(Exceptionex)
{
lblMessage.Text=string.Format("Anerrorhasoccurred:{0}",ex.ToString());
}
//TODO:Putthisintry/catchaswell
//TODO:Feelslikethisistoomuchbusinesslogic.ShouldbemovedtoOrderDetailconstructor?
varproductRepository=newProductRepository();
varproduct=productRepository.GetProductById(_productId);
varorderDetail=newOrderDetail()
{
Discount=0.0F,
ProductId=_productId,
Quantity=quantity,
Product=product,
UnitPrice=product.UnitPrice
};
cart.OrderDetails.Add(orderDetail);
Session["Cart"]=cart;
Response.Redirect("~/ViewCart.aspx");
}
原文链接:
http://www.jxszl.com/biancheng/C/556681.html