public decimal GetPriceWithDiscount(int count, IDiscountCard discountCard) { if (this._singlePricingRule == null) { throw new SinglePriceNotSetException(this.Name); } decimal PriceWithDiscountCard(int productsCount) { var price = this.GetFullPrice(productsCount); if (discountCard != null) { price = discountCard.Apply(price); } return(price); } if (this._volumePricingRule == null) { return(PriceWithDiscountCard(count)); } int volumesCount = count / this._volumePricingRule.Count; int singlesCount = count % this._volumePricingRule.Count; var totalPrice = volumesCount * this._volumePricingRule.Price + PriceWithDiscountCard(singlesCount); return(totalPrice); }
public PurchaseInformaton ProcessPurchase(decimal purchaseValue, IDiscountCard card) { if (purchaseValue < 0) { throw new ArgumentException(nameof(purchaseValue), $"{nameof(purchaseValue)} cannot be less than 0"); } return(new PurchaseInformaton { DiscountRate = card.DiscountRate, PurchaseValue = purchaseValue }); }
public void FinishSale() { var totalWithoutDiscount = 0m; foreach (var(code, quantity) in _scannedProducts) { totalWithoutDiscount += _knownProducts[code].CalculatePrice(quantity, 0).FullPrice; } _discountCard.AddAmount(totalWithoutDiscount); _discountCard = DiscountCard.None; _scannedProducts.Clear(); }
public string Calculate(IDiscountCard card, decimal purchase) { card.CalculateDiscount(); var discount = purchase * card.DiscountRate; var total = purchase - discount; var result = new StringBuilder(); result.AppendLine($"Purchase value: ${purchase:F2}"); result.AppendLine($"Discount rate: {card.DiscountRate * 100:F1}%"); result.AppendLine($"Discount: ${discount:F2}"); result.AppendLine($"Total: ${total:F2}"); return(result.ToString().TrimEnd()); }
public static string Pay(ICart ShoppingCart, IDiscountCard Card) { double cardDiscountRate = Card.DiscountRate; double purchaseValue = ShoppingCart.PurchaseValue; double purchaseDiscount = CalculatePurchaseDiscount(purchaseValue, cardDiscountRate); double totalAmount = CalculateTotalAmount(purchaseValue, purchaseDiscount); string owner = Card.CardHolder.FulName; StringBuilder InvoiceBuilder = new StringBuilder(); InvoiceBuilder.Append(string.Concat(PURCHASE_VALUE, purchaseValue.ToString("C"))).Append(Environment.NewLine) .Append(string.Concat(DISCOUNT_RATE, cardDiscountRate.ToString() + '%')) .Append(Environment.NewLine) .Append(string.Concat(PURCHASE_DISCOUNT, purchaseDiscount.ToString("C"))) .Append(Environment.NewLine) .Append(string.Concat(TOTAL_AMOUNT, totalAmount.ToString("C"))) .Append(Environment.NewLine) .Append(string.Concat(BUYER_OWNER, owner)); return(InvoiceBuilder.ToString()); }
public void ApplyDiscountCard(IDiscountCard discountCard) { this._cart.ApplyCard(discountCard); }
public void IUseDiscountCard(int percent) { this._discountCard = new DiscountCard(percent); this._terminal.ApplyDiscountCard(this._discountCard); }
public DiscountCardDiscount(IDiscountCard discountCard) { _discountCard = discountCard; }
public void ApplyCard(IDiscountCard discountCard) { this.DiscountCard = discountCard; this.PriceWithDiscount = this._cartItems.Values.Sum(ci => ci.GetPriceWithDiscount(discountCard)); }
public void SetDiscountCard(IDiscountCard discountCard) { Ensure.That(discountCard).IsNotNull(); _discountCard = discountCard; }
public decimal GetPriceWithDiscount(IDiscountCard discountCard) => this.Product.GetPriceWithDiscount(this.Count, discountCard);