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);
        }
Example #2
0
        private PromotionReward AddCatalogReward(Promotion promotion, decimal amount, RewardAmountType amountType)
        {
            var promotionReward = new CatalogItemReward
            {
                Amount       = amount,
                AmountTypeId = amountType.GetHashCode(),
                PromotionId  = promotion.PromotionId
            };

            MarketingRepository.Add(promotionReward);
            MarketingRepository.UnitOfWork.Commit();

            return(promotionReward);
        }
Example #3
0
        private Promotion AddCatalogPromotion(string catalogId, string expression, string promotionName = "test")
        {
            var promotion = new CatalogPromotion
            {
                Name                = promotionName,
                CatalogId           = catalogId,
                PredicateSerialized = expression,
                Status              = "Active",
                StartDate           = DateTime.UtcNow,
            };

            MarketingRepository.Add(promotion);
            MarketingRepository.UnitOfWork.Commit();

            return(promotion);
        }