本文整理汇总了C#中Cart类的典型用法代码示例。如果您正苦于以下问题:C# Cart类的具体用法?C# Cart怎么用?C# Cart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cart类属于命名空间,在下文中一共展示了Cart类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: btnAddToCart_Click
protected void btnAddToCart_Click(object sender, EventArgs e)
{
Cart cart;
if (Session["Cart"] is Cart)
cart = Session["Cart"] as Cart;
else
cart = new Cart();
short quantity = 1;
try
{
quantity = Convert.ToInt16(txtQuantity.Text);
}
catch (Exception ex)
{
lblMessage.Text = string.Format("An error has occurred: {0}", ex.ToString());
}
//TODO: Put this in try/catch as well
//TODO: Feels like this is too much business logic. Should be moved to OrderDetail constructor?
var productRepository = new ProductRepository();
var product = productRepository.GetProductById(_productId);
var orderDetail = new OrderDetail()
{
Discount = 0.0F,
ProductId = _productId,
Quantity = quantity,
Product = product,
UnitPrice = product.UnitPrice
};
cart.OrderDetails.Add(orderDetail);
Session["Cart"] = cart;
Response.Redirect("~/ViewCart.aspx");
}
开发者ID:yonglehou,项目名称:WebGoat.Net-1,代码行数:33,代码来源:Product.aspx.cs
示例2: ChangeStatus
public string ChangeStatus(int id = 0, int statusID = 0) {
Profile p = ViewBag.profile;
Cart order = new Cart();
order = order.GetByPayment(id);
order.SetStatus(statusID, p.first + " " + p.last);
return "success";
}
开发者ID:curt-labs,项目名称:CURTeCommerce,代码行数:7,代码来源:OrdersController.cs
示例3: UpdateSession
private void UpdateSession()
{
if (HttpContext.Session["Cart"] == null)
HttpContext.Session["Cart"] = cart;
else
cart = HttpContext.Session["Cart"] as Cart<Product>;
}
开发者ID:phamxuanlu,项目名称:MVC4-MobileStoreWeb,代码行数:7,代码来源:CartController.cs
示例4: Checkout
public ViewResult Checkout(Cart cart, Address address, bool mainAddress, string shipMethod)
{
if(!cart.Lines.Any()) ModelState.AddModelError("","Sorry, your cart is empty!");
var user = AuthHelper.GetUser(HttpContext, new EfUserRepository());
if (mainAddress) //если основной, то перезаписываем
{
if (address.AddressID == 0) //на случай, если пользователь не заполнил свой адрес в профиле
{
address.ModifiedDate = DateTime.Now;
address.rowguid = Guid.NewGuid();
_addressRepository.SaveToAddress(address);
_addressCustomerRepository.SaveToCustomerAddress(_addressCustomerRepository.BindCustomerAddress(
user, address));
}
else
{
_addressRepository.SaveToAddress(address);
}
}
else // иначе добавляем новый
{
address.AddressID = 0;
address.ModifiedDate = DateTime.Now;
address.rowguid = Guid.NewGuid();
_addressRepository.SaveToAddress(address);
}
if (ModelState.IsValid)
{
_orderProcessor.Processor(cart, user,address, shipMethod);
cart.Clear();
return View("Completed");
}
return View("Checkout");
}
开发者ID:kaban4ik1994,项目名称:E-shop,代码行数:34,代码来源:CartController.cs
示例5: Cannot_Checkout_Empty_Cart
public void Cannot_Checkout_Empty_Cart()
{
// Arrange - create a mock order processor
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// Arrange - create an empty cart
Cart cart = new Cart();
// Arrange - create shipping details
ShippingDetails shippingDetails = new ShippingDetails();
// Arrange - create an instance of the controller
CartController target = new CartController(null, mock.Object);
// Act
var result = target.Checkout(cart, shippingDetails);
// Assert check that the order hasn't been passed on to the processor
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never);
// Assert - check that the method is returning the default view
Assert.AreEqual("", result.ViewName);
// Assert - check that we are passing an invalid model to the view
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
开发者ID:hjgraca,项目名称:SportsStore,代码行数:26,代码来源:CartTests.cs
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
this.CurrentCart = Cart.GetCartFromSession(Session);
if (this.CurrentCart == null) throw new CartException("Cannot load cart data from session");
if (this.CurrentCart.BillingLocation == null) throw new CartException("Incomplete Cart (Billing)");
if (this.CurrentCart.ShippingLocation == null) throw new CartException("Incomplete Cart (Shipping)");
if (this.CurrentCart.Payment == null) throw new CartException("Incomplete Cart (Payment)");
if (this.CurrentCart.Dirty) this.CurrentCart.Clean();
string locationsummarypath = String.Format("{0}/locationsummary.ascx", Constants.UserControls.CHECKOUT_CONTROLS_DIR);
string paymentsummarypath = String.Format("{0}/paymentsummary.ascx", Constants.UserControls.CHECKOUT_CONTROLS_DIR);
string shippingoptionsummarypath = String.Format("{0}/shippingoptionsummary.ascx", Constants.UserControls.CHECKOUT_CONTROLS_DIR);
string itemsummarypath = String.Format("{0}/itemsummary.ascx", Constants.UserControls.CHECKOUT_CONTROLS_DIR);
BillingSummaryPlaceholder.Controls.Add(Helper.LoadUserControl(Page, locationsummarypath, CurrentCart.BillingLocation));
ShippingSummaryPlaceholder.Controls.Add(Helper.LoadUserControl(Page, locationsummarypath, CurrentCart.ShippingLocation));
ShippingOptionSummaryPlaceholder.Controls.Add(Helper.LoadUserControl(Page, shippingoptionsummarypath, CurrentCart));
orderid = Convert.ToInt32(Request.QueryString["id"]);
POrder = Convert.ToInt32(Request.QueryString["po"]);
//PaymentSummaryPlaceholder.Controls.Add(Helper.LoadUserControl(Page, paymentsummarypath, CurrentCart.Payment));
ItemsSummaryPlaceholder.Controls.Add(Helper.LoadUserControl(Page, itemsummarypath, CurrentCart));
}
catch (CartException ex)
{
Page.Controls.Add(new LiteralControl("There was an error loading your cart"));
}
}
开发者ID:hugovin,项目名称:shrimpisthefruitofthesea,代码行数:31,代码来源:print_order.aspx.cs
示例7: AddToCart
public void AddToCart(Album album)
{
// Get the matching cart and album instances
var cartItem = storeDB.Carts.SingleOrDefault(
c => c.CartId == ShoppingCartId
&& c.AlbumId == album.AlbumId);
if (cartItem == null)
{
// Create a new cart item if no cart item exists
cartItem = new Cart
{
AlbumId = album.AlbumId,
CartId = ShoppingCartId,
Count = 1,
DateCreated = DateTime.Now
};
storeDB.Carts.Add(cartItem);
}
else
{
// If the item does exist in the cart, then add one to the quantity
cartItem.Count++;
}
// Save changes
storeDB.SaveChanges();
}
开发者ID:bothaj,项目名称:Kronos,代码行数:26,代码来源:ShoppingCart.cs
示例8: ButtonAdd2Cart_Click
/// <summary>
/// "放入购物车"按钮单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ButtonAdd2Cart_Click(object sender, System.EventArgs e)
{
if (Session["user_id"] == null)
Page.Response.Redirect("Login.aspx?in=1");
Cart cart = new Cart();
Hashtable ht = new Hashtable();
ArrayList selectedBooks = this.GetSelected();
//如果用户没有选择,就单击该按钮,则给出警告
if (selectedBooks.Count == 0)
{
Response.Write("<Script Language=JavaScript>alert('请选择图书!');</Script>");
return;
}
//循环将选择的图书加入到购物篮中
foreach (int bookId in selectedBooks)
{
ht.Clear();
ht.Add("UserId", Session["user_id"].ToString());
ht.Add("BookId", bookId);
ht.Add("Amount", TextBoxAmount.Text.Trim());
cart.Add(ht);
}
Response.Redirect("CartView.aspx");
}
开发者ID:JohnToCoder,项目名称:MyBookShop_1,代码行数:32,代码来源:BookList.aspx.cs
示例9: PutCart
public async Task<IHttpActionResult> PutCart(int id, Cart cart)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != cart.Id)
{
return BadRequest();
}
db.Entry(cart).State = EntityState.Modified;
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!CartExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
开发者ID:Liutabu,项目名称:Restaurant,代码行数:32,代码来源:TablesController.cs
示例10: btnAdd_Click
protected void btnAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
string clientId = Context.User.Identity.GetUserId();
if (clientId != null)
{
int id = Convert.ToInt32(Request.QueryString["id"]);
int amount = Convert.ToInt32(ddlAmount.SelectedValue);
Cart cart = new Cart
{
Amount = amount,
ClientID = clientId,
DatePurchased = DateTime.Now,
IsInCart = true,
ProductID = id
};
CartModel model = new CartModel();
lblResult.Text = model.InsertCart(cart);
}
else
{
lblResult.Text = "Please log in to order items";
}
}
}
开发者ID:henrypedersen77,项目名称:GarageManagerMaster,代码行数:29,代码来源:Product.aspx.cs
示例11: AddToCart
public void AddToCart(Product product)
{
// Get the matching cart and product instances
var cartItem = _cartAppService.Find(
c => c.CartId == ShoppingCartId &&
c.ProductId == product.ProductId).SingleOrDefault();
if (cartItem == null)
{
// Create a new cart item if no cart item exists
cartItem = new Cart
{
ProductId = product.ProductId,
CartId = ShoppingCartId,
Count = 1,
DateCreated = DateTime.Now
};
_cartAppService.Create(cartItem);
}
else
{
// If the item does exist in the cart, then add one to the quantity
cartItem.Count++;
}
}
开发者ID:MrWooJ,项目名称:WJStore,代码行数:26,代码来源:ShoppingCart.cs
示例12: btnAdd_Click
protected void btnAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
//get the id of the current logged in user
string clientId = Context.User.Identity.GetUserId();
//implement a check to make sure only logged in user can order a product
if (clientId != null)
{
int id = Convert.ToInt32(Request.QueryString["id"]);
int amount = Convert.ToInt32(ddlAmount.SelectedValue);
Cart cart = new Cart
{
Amount = amount,
ClientID = clientId,
DatePurchased = DateTime.Now,
IsInCart = true,
ProductID = id
};
CartModel cartModel = new CartModel();
lblResult.Text = cartModel.InsertCart(cart);
Response.Redirect("~/Index.aspx");
}
else
{
lblResult.Text = "Please log in to order items";
}
}
}
开发者ID:SaifAsad,项目名称:garager,代码行数:32,代码来源:Product.aspx.cs
示例13: ReleaseCart
public Cart ReleaseCart(decimal receivedTax)
{
if (receivedTax < CartTax)
{
throw new ApplicationException("Call the police!");
}
else
{
this.collectedTax += receivedTax;
}
Cart currentCart;
if (this.freeCarts.Count == 0)
{
currentCart = new Cart();
}
else
{
int lastCart = this.freeCarts.Count - 1;
currentCart = this.freeCarts[lastCart];
this.freeCarts.RemoveAt(lastCart);
}
return currentCart;
}
开发者ID:kidroca,项目名称:high-quality-code-2015-homeworks,代码行数:26,代码来源:CartsPool.cs
示例14: AddToCart
public void AddToCart(int id)
{
// Retrieve the product from the database.
ShoppingCartId = GetCartId();
var cartItem = db.Carts.SingleOrDefault(
c => c.CartID == ShoppingCartId
&& c.ProductID == id);
if (cartItem == null)
{
cartItem = new Cart
{
ItemID = Guid.NewGuid().ToString(),
ProductID = id,
CartID = ShoppingCartId,
Product = db.Products.SingleOrDefault(
p => p.ProductID == id),
Quantity = 1,
DateCreated = DateTime.Now
};
db.Carts.Add(cartItem);
}
else
{
cartItem.Quantity++;
}
db.SaveChanges();
}
开发者ID:pttan94,项目名称:DemoCloud,代码行数:29,代码来源:ShoppingCartActions.cs
示例15: AddToCart
public RedirectToRouteResult AddToCart(int Id, int quantity)
{
cart = getCart();
Product p = db.Products.Where(x => x.Id == Id).SingleOrDefault();
cart.AddItem(p, quantity);
return RedirectToAction("Index", "Shop");
}
开发者ID:n-alex-white,项目名称:MallowAndWhite,代码行数:7,代码来源:CartController.cs
示例16: ChangeQuantity
public RedirectToRouteResult ChangeQuantity(Cart cart, int productId, string returnUrl, int quantity=0)
{
if (quantity < 1) quantity = 1;
var product = _repository.Products.FirstOrDefault(p => p.ProductID == productId);
if (product != null) cart.ChangeQuantity(product, quantity);
return RedirectToAction("Index", new {returnUrl});
}
开发者ID:kaban4ik1994,项目名称:E-shop,代码行数:7,代码来源:CartController.cs
示例17: Initialize
/// <summary>
/// Initializes the specified cart.
/// </summary>
/// <param name="cart">The cart.</param>
public virtual void Initialize(Cart cart)
{
Assert.ArgumentNotNull(cart, "cart");
this.LineItemCount = ((CommerceCart)cart).LineItemCount;
this.Total = ((CommerceTotal)cart.Total).Subtotal.ToCurrency(StorefrontConstants.Settings.DefaultCurrencyCode);
}
开发者ID:Brad-Christie,项目名称:sccs-demo,代码行数:11,代码来源:MiniCartBaseJsonResult.cs
示例18: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["MYCART"] == null)
{
Session["MYCART"] = myCart;
}
else
{
myCart = (Cart)(Session["MYCART"]);
}
string PID = Request["PID"];
string sql = "SELECT * FROM Products WHERE ProductId=" + PID;
ds = DBFunctions.GetDataSetDB(sql);
lblProdDesc.Text = ds.Tables[0].Rows[0]["ProductSDesc"].ToString();
lblPrice.Text = "$" + ds.Tables[0].Rows[0]["Price"].ToString();
Session["PRICE"] = ds.Tables[0].Rows[0]["Price"].ToString();
Session["PRODDESC"] = ds.Tables[0].Rows[0]["ProductSDesc"].ToString();
Session["PRODUCTID"] = ds.Tables[0].Rows[0]["ProductId"].ToString();
}
catch (Exception ex)
{
lblStatus.Text = ex.Message;
}
}
开发者ID:weifengli001,项目名称:webappdev,代码行数:28,代码来源:ProductDisplay.aspx.cs
示例19: initCartData
void initCartData()
{
var cart = new Cart()
{
CreateTime = DateTime.Now,
Id = 1,
};
SaleItem saleItem = new SaleItem()
{
Cart = cart,
CartId = 1,
Id = 1,
ProductId = 1,
Quantity = 10
};
SaleItem saleItem2 = new SaleItem()
{
Cart = cart,
CartId = 1,
Id = 2,
ProductId = 2,
Quantity = 10
};
cart.SaleItems.Add(saleItem);
cart.SaleItems.Add(saleItem2);
fakeShoppingCartDbContext.Carts.Add(cart);
fakeShoppingCartDbContext.SaleItems.Add(saleItem);
fakeShoppingCartDbContext.SaleItems.Add(saleItem2);
}
开发者ID:yangyu0311,项目名称:ShoppingCart,代码行数:29,代码来源:CartUnitTesting.cs
示例20: Index
public ViewResult Index(Cart cart, string returnUrl)
{
CartIndexViewModel model = new CartIndexViewModel();
model.Cart = cart;
model.ReturnUrl = returnUrl;
return View(model);
}
开发者ID:chatopaniagua,项目名称:TiendaDeportiva,代码行数:7,代码来源:CartController.cs
注:本文中的Cart类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论