public void RegisterToUsePromotion(IPromotionEvaluationContext context, Promotion promotion) { var promotionUsage = new PromotionUsage { CouponCode = context.CouponCode, MemberId = context.CustomerId, PromotionId = promotion.PromotionId, OrderGroupId = ((OrderGroup)context.ContextObject).OrderGroupId }; _marketingRepository.Add(promotionUsage); _marketingRepository.UnitOfWork.Commit(); }
private PromotionUsage UpdatePromotionUsage(ICollection<PromotionUsage> currentUsages, Discount discount) { var usage = currentUsages.FirstOrDefault(x => x.PromotionId == discount.PromotionId); if (usage != null) { usage.Status = (int)UsageStatus; usage.UsageDate = DateTime.UtcNow; } else { usage = new PromotionUsage { CouponCode = discount.DiscountCode, MemberId = CustomerSessionService.CustomerSession.CustomerId, OrderGroupId = CurrentOrderGroup.OrderGroupId, PromotionId = discount.PromotionId, Status = (int)UsageStatus, UsageDate = DateTime.UtcNow }; //Need to add here too to avoid duplicates currentUsages.Add(usage); MarketingRepository.Add(usage); } return usage; }