public void ApplyDiscount(IDiscountable item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.DiscountParameter < 2) { throw new InvalidOperationException("Invalid parameter"); } if (item.DiscountRuleType != DiscountRuleType.BuyManyGetOneFree) { throw new InvalidOperationException("Invalid Discount rule applied"); } if (item.Quantity == 1) { item.AfterDiscountPrice = item.UnitPrice; return; } var anySingles = item.Quantity % item.DiscountParameter; item.AfterDiscountPrice = anySingles == 0 ? item.UnitPrice * item.Quantity * (item.DiscountParameter - 1) / item.DiscountParameter : item.UnitPrice * ((item.Quantity - anySingles) * (item.DiscountParameter - 1) / item.DiscountParameter + anySingles); item.AfterDiscountPrice = Math.Round(item.AfterDiscountPrice, 2); }
public void ApplyDiscount(IDiscountable item) { if (!item.DiscountRuleType.HasValue) { item.AfterDiscountPrice = item.UnitPrice * item.Quantity; return; } var discountRule = _discountRuleFactory.ResolveDiscountRule(item.DiscountRuleType.Value); discountRule.ApplyDiscount(item); }
public void ApplyDiscount(IDiscountable item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.DiscountRuleType != DiscountRuleType.None) { throw new InvalidOperationException("Invalid Discount rule applied"); } item.AfterDiscountPrice = item.Quantity * item.UnitPrice; }
public void ApplyDiscount(IDiscountable item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.DiscountRuleType != DiscountRuleType.Percentage) { throw new InvalidOperationException("Invalid Discount rule applied"); } var fullPrice = item.Quantity * item.UnitPrice; item.AfterDiscountPrice = Math.Round(fullPrice - fullPrice * item.DiscountParameter / 100, 2); }
public double disCountSell(IDiscountable d) { Apple apple = d as Apple; if (apple.weight < 10) { return(apple.weight * apple.unitPrice); } else if (apple.weight >= 10 && apple.weight <= 50) { return(apple.weight * apple.unitPrice * 0.88); } else { return(apple.weight * apple.unitPrice * 0.6); } }