public ActionResult <ActivePromotionsModel> GetActivePromotions(string itemName) { var returnObject = new ActivePromotionsModel(); var promotionForItem = new DiscountsFactory().GetPromotions(itemName); returnObject.DiscountRunning = promotionForItem.DiscountOffered; returnObject.ItemName = itemName; returnObject.NoOfItems = promotionForItem.NoOfItems; return(returnObject); }
private double CheckPromoDiscount(double unitPrice, AddItemRequestModel item) { var promotionForItem = new DiscountsFactory().GetPromotions(item.ItemType); var OnDiscountPrice = (item.ItemQuantity / promotionForItem.NoOfItems) * promotionForItem.DiscountOffered; if (!Flag) { isPromoApplied = OnDiscountPrice > 0; Flag = true; } var OffDiscountPrice = (item.ItemQuantity % promotionForItem.NoOfItems) * unitPrice; return(OnDiscountPrice + OffDiscountPrice); }
public double GenerateBillForCAndD(IList <AddItemRequestModel> items) { var promotionForItem = new DiscountsFactory().GetPromotions(items.FirstOrDefault().ItemType); var minimumCommonQtyinBoth = items.Select(x => x.ItemQuantity).Min(); var OnDiscountPrice = minimumCommonQtyinBoth * promotionForItem.DiscountOffered; if (!Flag) { isPromoApplied = OnDiscountPrice > 0; Flag = true; } var itemWithMoreQty = items.Where(x => x.ItemQuantity > minimumCommonQtyinBoth); var unitPrice = GetUnitPriceOfItem(itemWithMoreQty.FirstOrDefault()); var OffDiscountPrice = (itemWithMoreQty.FirstOrDefault().ItemQuantity - minimumCommonQtyinBoth) * unitPrice; return(OffDiscountPrice + OnDiscountPrice); }