예제 #1
0
        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);
        }
예제 #2
0
        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
            });
        }
예제 #3
0
        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();
        }
예제 #4
0
        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());
        }
예제 #5
0
        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());
        }
예제 #6
0
 public void ApplyDiscountCard(IDiscountCard discountCard)
 {
     this._cart.ApplyCard(discountCard);
 }
예제 #7
0
 public void IUseDiscountCard(int percent)
 {
     this._discountCard = new DiscountCard(percent);
     this._terminal.ApplyDiscountCard(this._discountCard);
 }
 public DiscountCardDiscount(IDiscountCard discountCard)
 {
     _discountCard = discountCard;
 }
예제 #9
0
 public void ApplyCard(IDiscountCard discountCard)
 {
     this.DiscountCard      = discountCard;
     this.PriceWithDiscount = this._cartItems.Values.Sum(ci => ci.GetPriceWithDiscount(discountCard));
 }
예제 #10
0
        public void SetDiscountCard(IDiscountCard discountCard)
        {
            Ensure.That(discountCard).IsNotNull();

            _discountCard = discountCard;
        }
예제 #11
0
 public decimal GetPriceWithDiscount(IDiscountCard discountCard)
 => this.Product.GetPriceWithDiscount(this.Count, discountCard);