/// <summary> /// <see cref="ICheckout.GetTotalPrice"/> /// </summary> /// <returns>The total price of scanned products including special offers.</returns> public int GetTotalPrice() { int totalPrice = 0; IList <Product> processedProducts = new List <Product>(); foreach (KeyValuePair <string, IList <string> > products in this.scannedProducts) { Product productMaster = this.productInventory.Get(products.Key); MultiDeal multiDealMaster = productMaster.MultiDeal; int productsCount = products.Value.Count; if (productMaster.IsMultiDealValid(DateTime.Now)) { while (productsCount >= multiDealMaster.Units) { totalPrice += multiDealMaster.MultiDealPrice; productsCount -= multiDealMaster.Units; } } while (productsCount > 0) { totalPrice += productMaster.Price; productsCount -= 1; } } return(totalPrice); }
/// <summary> /// Constructor for a Product with optional MultiDeal reference /// (defaults to a non-valid instance). /// </summary> /// <param name="sku">The SKU of the product.</param> /// <param name="price">The price of the product.</param> /// <param name="multiDeal">The (optional) MultiDeal of the product.</param> public Product(string sku, int price, MultiDeal multiDeal = null) { this.Sku = string.IsNullOrEmpty(sku) ? throw new ArgumentNullException(nameof(sku)) : sku; this.Price = price > 1 ? price : throw new ArgumentException("Price must be greater than zero."); this.MultiDeal = multiDeal == null ? new MultiDeal() : multiDeal; }