Exemple #1
0
        public override void CalculatePrice()
        {
            Item milkItem = Items.FirstOrDefault(x => x.Product.Code == "Milk");

            if (milkItem?.Quantity > 3)
            {
                int    discountQoef = milkItem.Quantity / 4;
                double discount     = discountQoef * milkItem.Product.Price;

                milkItem.ProductTotal = Math.Round(milkItem.ProductTotal - discount, 2);
                AppliedDiscounts.Add(Discounts.MilkDiscount);
            }
        }
        public override void CalculatePrice()
        {
            Item butterItem = Items.FirstOrDefault(x => x.Product.Code == "Butter");
            Item breadItem  = Items.FirstOrDefault(x => x.Product.Code == "Bread");

            if (butterItem?.Quantity >= 2 && breadItem != null)
            {
                int discountQoef = butterItem.Quantity / 2 > breadItem.Quantity ? breadItem.Quantity : butterItem.Quantity / 2;

                breadItem.ProductTotal = Math.Round(breadItem.ProductTotal - (discountQoef * breadItem.Product.Price * 0.5), 2);

                AppliedDiscounts.Add(Discounts.ButterDiscount);
            }
        }