private float GetOffPrice(float originalPrice, MarkedItem item) { if (item.MarkedGets.Count == 0) { return(originalPrice); } float offPrice = 0; foreach (var get in item.MarkedGets) { offPrice += get.Value; } return(offPrice); }
public object ApplyPromos(List <Promotion> promotions, List <Item> cartItems) { if (cartItems == null || cartItems.Count == 0) { throw new NotSupportedException("Cart cannot be null."); } if (promotions == null || promotions.Count == 0) { throw new NotSupportedException("No promotions to apply."); } List <MarkedItem> markedItems = new List <MarkedItem>(); foreach (var item in cartItems) { MarkedItem mItem = new MarkedItem() { Item = item, MarkedBuys = new Dictionary <string, bool>(), MarkedGets = new Dictionary <string, float>() }; markedItems.Add(mItem); } foreach (var promo in promotions) { markedItems = ApplyPromo(promo, markedItems); } var prices = ComputeTotalPrices(markedItems); PromofiedCart modifiedCart = new PromofiedCart() { items = markedItems, TotalPrice = prices.Item1, TotalOffPrice = prices.Item2 }; return(modifiedCart); }