Esempio n. 1
0
 public static PromoPackage GetPromoPackage(Order order)
 {
     foreach (PromoPackage promoPackage in promoPackages)
     {
         if (promoPackage.IsEligible(order))
         {
             return promoPackage;
         }
     }
     return null;
 }
Esempio n. 2
0
        private int CalculateDiscount(Order order)
        {
            if (!Inventory.IsPromoOrder(order))
            {
                return 0;
            }

            PromoPackage promoPackage = Inventory.GetPromoPackage(order);

            return promoPackage.CaclulateDiscount();
        }
Esempio n. 3
0
        public bool CustomerBuysBooksWithTitle(string customerName, int amount, String title)
        {
            Domain.Books.Book book = Inventory.FindByTitle(title);

            Domain.Customers.Customer customer = CustomerRepository.FindByName(customerName);

            var order = new Order(customer);

            order.AddBook(amount, book);

            bookService.BuyBooks(order);

            return true;
        }
Esempio n. 4
0
        public void BuyBooks(Order order)
        {
            int discount = CalculateDiscount(order);

            order.ApplyDiscount(discount);

            // Then deduct the inventory
            foreach (Book book in order.Books)
            {
                int amount = order.GetAmount(book);

                Inventory.DeductInventory(book, amount);
            }
        }
Esempio n. 5
0
 public bool IsEligible(Order order)
 {
     return order.ContainsBook(book1) && order.ContainsBook(book2);
 }
Esempio n. 6
0
 public static bool IsPromoOrder(Order order)
 {
     foreach (PromoPackage promoPackage in promoPackages)
     {
         if (promoPackage.IsEligible(order))
         {
             return true;
         }
     }
     return false;
 }