本文整理汇总了C#中ShoppingCart类的典型用法代码示例。如果您正苦于以下问题:C# ShoppingCart类的具体用法?C# ShoppingCart怎么用?C# ShoppingCart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ShoppingCart类属于命名空间,在下文中一共展示了ShoppingCart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructorSpecifications
public void ConstructorSpecifications()
{
ShoppingCart cart = null;
"Given new ShoppingCart".Context(() => cart = new ShoppingCart());
"number of Items is 0".Assert(() => cart.Items.Count.ShouldEqual(0));
}
示例2: ViewCartDialog
public ViewCartDialog(ShoppingCart.Cart cart)
{
InitializeComponent();
this.cart = cart;
totalLabel.Text = string.Format("${0:#.00}", cart.getTotalPrice());
totalShippingLabel.Text = string.Format("${0:#.00}", cart.getTotalShipping());
}
示例3: EventsToShoppingCart
private static IEnumerable<object> EventsToShoppingCart(IEnumerable<dynamic> source)
{
foreach (var @event in source)
{
var cart = new ShoppingCart { Id = @event.ShoppingCartId };
{
switch ((string)@event.Type)
{
case "Create":
cart.Customer = new ShoppingCartCustomer
{
Id = @event.CustomerId,
Name = @event.CustomerName
};
break;
case "Add":
cart.AddToCart(@event.ProductId, @event.ProductName, (decimal)@event.Price, 1);
break;
case "Remove":
cart.AddToCart(@event.ProductId, @event.ProductName, (decimal)@event.Price, -1);
break;
}
}
yield return new
{
@event.__document_id,
ShoppingCartId = cart.Id,
Aggregate = cart
};
}
}
示例4: PutShoppingCart
public async Task<IHttpActionResult> PutShoppingCart(int id, ShoppingCart shoppingCart)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != shoppingCart.Id)
{
return BadRequest();
}
db.Entry(shoppingCart).State = EntityState.Modified;
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ShoppingCartExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
示例5: ApplyCoupon
public bool ApplyCoupon(ShoppingCart cart, string coupon)
{
if (String.IsNullOrWhiteSpace(coupon))
{
return false;
}
var oldCoupon = cart.CouponCode;
cart.CouponCode = coupon;
var context = PricingContext.CreateFrom(cart);
new PricingPipeline().Execute(context);
if (context.AppliedPromotions.Any(p => p.RequireCouponCode && p.CouponCode == coupon))
{
return true;
}
cart.CouponCode = oldCoupon;
_repository.Database.SaveChanges();
return false;
}
示例6: UseExtentionEnumerable
public ViewResult UseExtentionEnumerable()
{
// create and populate Shoppingcart
ShoppingCart cart = new ShoppingCart
{
Products = new List<Product>
{
new Product {Name = "Kayak",Price = 275M },
new Product {Name = "Lifejacket",Price = 48.95M },
new Product {Name = "Soccer ball",Price = 19.5M },
new Product {Name = "Corner flag",Price = 34.95M }
}
};
Product[] productArray = {
new Product { Name = "Kayak", Price = 275M },
new Product { Name = "Lifejacket", Price = 48.95M },
new Product { Name = "Soccer ball", Price = 19.5M },
new Product { Name = "Corner flag", Price = 34.95M }
};
decimal cartTotal = cart.Totalprices();
decimal arrayTotal = productArray.Totalprices();
return View("Result", (object)String.Format("Total: {0:c}, Array Total: {1:c}", cartTotal, arrayTotal ));
}
示例7: GetCart
public static ShoppingCart GetCart(HttpContextBase context, IStoretUnitOfWork storetUnitOfWork)
{
var cart = new ShoppingCart();
_storetUnitOfWork = storetUnitOfWork;
cart.ShoppingCartId = GetCartId(context);
return cart;
}
示例8: DeleteShoppingCart
private void DeleteShoppingCart()
{
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.CartGuid = this.CartGUID;
ProcessGetShoppingCart getShoppingCart = new ProcessGetShoppingCart();
getShoppingCart.ShoppingCart = shoppingCart;
try
{
getShoppingCart.Invoke();
}
catch (Exception ex)
{
Response.Redirect("ErrorPage.aspx");
}
ProcessDeleteShoppingCartByGuid deleteCart = new ProcessDeleteShoppingCartByGuid();
deleteCart.ShoppingCart = getShoppingCart.ShoppingCart;
try
{
deleteCart.Invoke();
Utilities.DeleteCartGUID();
}
catch (Exception ex)
{
Response.Redirect("ErrorPage.aspx");
}
}
示例9: Delete
public object Delete(ShoppingCart.ShoppingCartItem request)
{
var success = ShoppingCarts.RemoveFromCart(UserId, request.Product.Id);
if (success) return new HttpResult(HttpStatusCode.NoContent, "");
return new HttpError(HttpStatusCode.BadRequest, "");
}
示例10: UseExtensionEnumerable
//http://localhost:50070/Home/UseExtensionEnumerable
public ViewResult UseExtensionEnumerable()
{
//A Type
IEnumerable<Product> products = new ShoppingCart {
Products = new List<Product>
{
new Product { Name="p1", Price=10 },
new Product { Name="p2", Price=20 },
new Product { Name="p3", Price=30 }
}
};
//B Type (배열도 IEnumerable 인터페이스를 구현하고 있다)
Product[] productArray =
{
new Product { Name="p1", Price=10 },
new Product { Name="P2", Price=20 },
new Product { Name="p3", Price=30 }
};
//Total
decimal cartTotal = products.TotalPrices();
decimal arrayTotal = productArray.TotalPrices();
return View("Result", (object)String.Format("Cart Total : {0}, Array Total: {1}", cartTotal, arrayTotal));
}
示例11: UpdateStockLevel
protected void UpdateStockLevel()
{
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.CartGuid = this.CartGUID;
ProcessGetShoppingCart getShoppingCart = new ProcessGetShoppingCart();
getShoppingCart.ShoppingCart = shoppingCart;
ProcessUpdateStockLevel updateStockLevel = new ProcessUpdateStockLevel();
try
{
getShoppingCart.Invoke();
}
catch (Exception ex)
{
Response.Redirect("ErrorPage.aspx");
}
updateStockLevel.ShoppingCart = getShoppingCart.ShoppingCart;
try
{
updateStockLevel.Invoke();
}
catch (Exception ex)
{
Response.Redirect("ErrorPage.aspx");
}
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
Cart = HttpContext.Current.Session["Cart"] as ShoppingCart;
if (Cart == null)
{
Cart = new ShoppingCart("ProductsGrid");
HttpContext.Current.Session["Cart"] = Cart;
}
ProductsGrid.DataSource = Cart.ToTable();
ProductsGrid.DataBind();
if (ProductsGrid.Rows.Count > 0)
{
CartTotal.Text = "<p class='total'>Grand Total: " String.Format("{0:c}", Cart.Total) "</p>";
}
else
{
CartBody.Text = "<p>Your cart is empty!</p>";
}
}
catch (Exception ex)
{
CartBody.Text = "<p>Error: " ex.Message "</p>";
}
}
}
示例13: getItemNumber
// Generates an item number based on the attributes of an Item object.
public static int getItemNumber(ShoppingCart.Item item)
{
int itemNumber = (int)item.getType() + 1;
itemNumber = (itemNumber * 10) + (int)item.getStain();
// Based on the type of the item, generate additional digits for the item number based on that Item_Types attributes.
if(item.getType() == ShoppingCart.Item.Item_Type.Board){
itemNumber = (itemNumber * 10) + (int)((ShoppingCart.Chalkboard)item).getMagneticType();
itemNumber = (itemNumber * 10) + (int)((ShoppingCart.Chalkboard)item).getFrameStyle();
itemNumber = (itemNumber * 10) + (int)((ShoppingCart.Chalkboard)item).getHangingDirection();
itemNumber = (itemNumber * 100) + (int)((ShoppingCart.Chalkboard)item).getLength();
itemNumber = (itemNumber * 100) + (int)((ShoppingCart.Chalkboard)item).getWidth();
}
else if(item.getType() == ShoppingCart.Item.Item_Type.Sconce){
// Item number multiplied by 10000000 to match length of chalkboard item number.
itemNumber = (itemNumber * 10000000) + (int)((ShoppingCart.Sconce)item).getHeight();
}
else if(item.getType() == ShoppingCart.Item.Item_Type.Box){
// Item number multiplied by 10000000 to match length of chalkboard item number.
itemNumber = (itemNumber * 10000000) + (int)((ShoppingCart.Box)item).getLength();
}
else if(item.getType() == ShoppingCart.Item.Item_Type.Organizer){
// Item number multiplied by 10000000 to match length of chalkboard item number.
itemNumber = (itemNumber * 10) + (int)((ShoppingCart.JarOrganizer)item).getJarCount();
itemNumber = (itemNumber * 1000000) + (int)((ShoppingCart.JarOrganizer)item).getWidth();
}
else if(item.getType() == ShoppingCart.Item.Item_Type.JarSconce){
// Item number multiplied by 10000000 to match length of chalkboard item number.
itemNumber = (itemNumber * 10) + (int)((ShoppingCart.JarSconce)item).getSconceCount();
itemNumber = (itemNumber * 1000000) + (int)((ShoppingCart.JarSconce)item).getHeight();
}
return itemNumber;
}
示例14: AddItemInputValidationSpecifications
public void AddItemInputValidationSpecifications()
{
ShoppingCart cart = null;
"Given new ShoppingCart".Context(() => cart = new ShoppingCart());
"AddItem throws when ArgumentNullException when null product name is passed".AssertThrows<ArgumentNullException>(() => cart.AddItem(null));
}
示例15: AssignPromotionsToShoppingCartItems
public void AssignPromotionsToShoppingCartItems(ShoppingCart cart) {
foreach (Item item in cart.GetItemsInCart()) {
if (promotionModel.HasPromotionForItem(item)) {
cart.AttachPromotionToItem(item, promotionModel.GetPromotionForItem(item));
}
}
}