Example #1
0
        private static void CalculateDiscountForNewCustomer()
        {
            var customer = new Customer();

            decimal discount = _discountCalculator.CalculateDiscountPercentage(customer);

            Console.WriteLine("New customer discount: ${0}", discount);
        }
        public decimal CalculateDiscountPercentage(Customer customer)
        {
            decimal discount = 0;

            foreach (var rule in _rules)
            {
                discount = Math.Max(rule.CalculateCustomerDiscount(customer), discount);
            }

            return discount;
        }
Example #3
0
        private static void CalculateDiscountForSenior()
        {
            var customer = new Customer {
                DateOfBirth = DateTime.Today.AddYears(-65).AddDays(-5),
                DateOfFirstPurchase = DateTime.Today.AddDays(-1)
            };

            decimal discount = _discountCalculator.CalculateDiscountPercentage(customer);

            Console.WriteLine("Senior customer discount: ${0}", discount);
        }
Example #4
0
        private static void CalculateDiscountFor5YearLoyalCustomerOnBirthday()
        {
            var customer = new Customer
            {
                DateOfBirth = DateTime.Today,
                DateOfFirstPurchase = DateTime.Today.AddYears(-5)
            };

            decimal discount = _discountCalculator.CalculateDiscountPercentage(customer);

            Console.WriteLine("5 year customer on birthday discount: ${0}", discount);
        }
Example #5
0
        private static void CalculateDiscountForVeteran()
        {
            var customer = new Customer
            {
                IsVeteran = true,
                DateOfFirstPurchase = DateTime.Today.AddDays(-1)
            };

            decimal discount = _discountCalculator.CalculateDiscountPercentage(customer);

            Console.WriteLine("Veteran customer discount: ${0}", discount);
        }