public Order(IShoppingCatalog catalog)
 {
     _catalog = catalog;
 }
Beispiel #2
0
 public void HandleOffers(Receipt receipt, Dictionary <Product, Offer> offers, IShoppingCatalog catalog)
 {
     foreach (var p in _productLine.Keys)
     {
         var quantity      = _productLine[p];
         var quantityAsInt = (int)quantity;
         if (offers.ContainsKey(p))
         {
             var      offer     = offers[p];
             var      unitPrice = catalog.GetUnitPrice(p);
             Discount discount  = null;
             var      x         = 1;
             if (p.Name == "Rubber Gloves" && offer.OfferType == SpecialOfferType.ThreeForTwo && quantityAsInt > 2)
             {
                 x = 3;
                 var numberOfXs     = quantityAsInt / x;
                 var discountAmount = (quantity * unitPrice) - ((numberOfXs * 2 * unitPrice) + quantityAsInt % 3 * unitPrice);
                 discount = new Discount(p, "3 for 2", discountAmount);
             }
             if (p.Name == "Stethoscope" && offer.OfferType == SpecialOfferType.ThreeForAmount && quantityAsInt >= 3)
             {
                 var discountAmount = (quantity * unitPrice) - (((quantityAsInt / 3) * 999) + (quantityAsInt % 3 * unitPrice));
                 discount = new Discount(p, "3 pcs for 999", discountAmount);
             }
             if (discount != null)
             {
                 receipt.AddDiscount(discount);
             }
         }
     }
 }