Skip to content

Instantly share code, notes, and snippets.

@pavsaund
Created October 19, 2016 11:41
Show Gist options
  • Save pavsaund/886ccd59bf0902c60ffd43707a61fb0b to your computer and use it in GitHub Desktop.
Save pavsaund/886ccd59bf0902c60ffd43707a61fb0b to your computer and use it in GitHub Desktop.
public class ShoppingCart
{
public IList<CartItem> Items { get; set; }
public decimal CartTotal { get; set; }
public void Add(CartItem item)
{
if (Items.Any(x => x.StockKeepingUnit == item.StockKeepingUnit))
{
var i = Items.First(x => x.StockKeepingUnit == item.StockKeepingUnit);
item.Qty += i.Qty;
}
else
{
Items.Add(item);
}
// Extra tracking we need to do for customer service and extra debug tracing
Track();
}
private void Track()
{
var t = Items.Sum(x => x.TotaPrice);
CartTotal = t;
CustomerTrackingService.TrackTotalInShoppingCart(t);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment