本文整理汇总了C#中ShoppingCart.AddToCart方法的典型用法代码示例。如果您正苦于以下问题:C# ShoppingCart.AddToCart方法的具体用法?C# ShoppingCart.AddToCart怎么用?C# ShoppingCart.AddToCart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShoppingCart
的用法示例。
在下文中一共展示了ShoppingCart.AddToCart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
};
}
}
示例2: Reduce
private static IEnumerable<object> Reduce(IEnumerable<dynamic> source)
{
foreach (var events in source
.GroupBy(@event => @event.ShoppingCartId))
{
var cart = new ShoppingCart { Id = events.Key };
foreach (var @event in events.OrderBy(x => x.Timestamp))
{
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);
break;
case "Remove":
cart.RemoveFromCart(@event.ProductId);
break;
}
}
yield return new
{
ShoppingCartId = cart.Id,
Aggregate = JObject.FromObject(cart)
};
}
}