Exemplo n.º 1
0
        public void ApplyBestCampaign(IEnumerable <Campaign> campaigns)
        {
            // Get all categories of product (get current and its ancestors categories)
            var productCategories = this.Product.GetAllCategories();

            //Only campaigns that has same category with product can be applied. So, filter campaigns if they are in those categories.
            var applicableCampaigns = campaigns.Where(c => productCategories.Contains(c.Category));

            foreach (var campaign in applicableCampaigns)
            {
                //Check if applicable and calculate the discount if its applicable otherwise discount is 0.
                var discountAmount = campaign.IsApplicable(this.OrderQuantity) ? campaign.CalculateDiscount(this.OrderQuantity * this.Product.UnitPrice) : 0;

                if (this.BestCampaignDiscount.DiscountAmount < discountAmount)
                {
                    this.BestCampaignDiscount = this.BestCampaignDiscount.Update(campaign, discountAmount);
                }
            }
        }
Exemplo n.º 2
0
 public ShoppingCartItem(Product product, double orderQuantity)
 {
     this.Product              = product;
     this.OrderQuantity        = orderQuantity;
     this.BestCampaignDiscount = new CampaignDiscountModel();
 }