Created
October 19, 2016 11:41
-
-
Save pavsaund/886ccd59bf0902c60ffd43707a61fb0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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