// We use AND logic for calculating count of possiable usages based on all buy items private int GetPossiableNumberOfUse(BuyXGetYPromotion promotion, IEnumerable <OrderToProduct> notPromoProducts) { var toReturn = 0; foreach (var buyItem in promotion.BuyItems) { var productRecord = notPromoProducts.FirstOrDefault(p => p.IdProduct == buyItem.IdProduct); if (productRecord == null) { toReturn = 0; break; } var maxUseForBuyItem = (int)Math.Floor(productRecord.QTY / buyItem.QTY); toReturn = toReturn == 0 ? maxUseForBuyItem : Math.Min(toReturn, maxUseForBuyItem); } return(toReturn); }
public Result <BasePromotion> Post([FromBody] BuyXGetYPromotion item) { return(_promotionService.AddPromotion(item)); }