/// <summary> /// Gets the quantity range. /// </summary> /// <param name="quantity">The quantity.</param> /// <returns></returns> public PromotionEntriesSet GetQuantityRange(decimal quantity) { decimal totalQuantity = 0; PromotionEntriesSet retVal = new PromotionEntriesSet(); foreach (PromotionEntry entry in Entries) { if (totalQuantity == quantity) { break; } PromotionEntry newEntry = (PromotionEntry)entry.Clone(); totalQuantity += entry.Quantity; if (totalQuantity > quantity) { newEntry.Quantity = quantity - (totalQuantity - entry.Quantity); totalQuantity = quantity; } if (newEntry.Quantity != 0) { retVal.Entries.Add(newEntry); } } // Copy owner id retVal.OwnerId = this.OwnerId; return(retVal); }
/// <summary> /// Initializes a new instance of the <see cref="PromotionContext"/> class. /// </summary> /// <param name="context">The context.</param> /// /// <param name="sourceEntries">The source entries.</param> /// <param name="targetEntries">The target entries.</param> public PromotionContext(IDictionary <string, object> context, PromotionEntriesSet sourceEntries, PromotionEntriesSet targetEntries) { _Context = context; _SourceEntriesSet = sourceEntries; _TargetEntriesSet = targetEntries; _ExclusiveGroups = new List <string>(); // Retrieve all the coupons customer entered if (context != null && context.ContainsKey(MarketingContext.ContextConstants.Coupons)) { Coupons = (List <string>)context[MarketingContext.ContextConstants.Coupons]; } else { Coupons = new List <string>(); } // Retrieve customer segments, it should be initialized beforehand if (context != null && context.ContainsKey(MarketingContext.ContextConstants.CustomerSegments)) { Segments = (List <int>)context[MarketingContext.ContextConstants.CustomerSegments]; } else { Segments = new List <int>(); } // Retrieve customer id, it should be initialized beforehand if (context != null && context.ContainsKey(MarketingContext.ContextConstants.CustomerId)) { CustomerId = (Guid)context[MarketingContext.ContextConstants.CustomerId]; } else { CustomerId = Guid.Empty; } // Retrieve promotion usage, it should be initialized beforehand if (context != null && context.ContainsKey(MarketingContext.ContextConstants.PromotionUsage)) { _PromotionUsageDto = (PromotionUsageDto)context[MarketingContext.ContextConstants.PromotionUsage]; } else { _PromotionUsageDto = null; } }
/// <summary> /// Makes the copy. /// </summary> /// <param name="codes">The codes.</param> /// <param name="exclude">if set to <c>true</c> [exclude].</param> /// <returns></returns> public PromotionEntriesSet MakeCopy(string[] codes, bool exclude) { PromotionEntriesSet newSet = new PromotionEntriesSet(); Func <PromotionEntry, PromotionEntriesSet> addEntry = x => { newSet.Entries.Add((PromotionEntry)x.Clone()); return(newSet); }; Entries.Where(x => { bool found = codes.Contains(x.CatalogEntryCode); return(exclude ? !found : found); }).Select(x => addEntry(x)).ToArray(); //foreach (string code in codes) //{ // PromotionEntry entry = this.FindEntryByCode(code); // if (entry != null) // { // newSet.Entries.Add(entry); // } //} // Copy owner id newSet.OwnerId = this.OwnerId; return(newSet); }