コード例 #1
0
        protected virtual CouponUsageRecordJobArgument GetJobArgumentsForCouponUsageRecord(CustomerOrder order)
        {
            var           objectId      = order.Id;
            IHasDiscounts hasDiscounts  = order;
            var           customerId    = order.CustomerId;
            var           customerName  = order.CustomerName;
            var           usageComparer = AnonymousComparer.Create((PromotionUsage x) => string.Join(":", x.PromotionId, x.CouponCode, x.ObjectId));
            var           result        = hasDiscounts.GetFlatObjectsListWithInterface <IHasDiscounts>()
                                          .Where(x => x.Discounts != null)
                                          .SelectMany(x => x.Discounts)
                                          .Where(x => !string.IsNullOrEmpty(x.Coupon))
                                          .Select(x => new PromotionUsage
            {
                CouponCode  = x.Coupon,
                PromotionId = x.PromotionId,
                ObjectId    = objectId,
                ObjectType  = hasDiscounts.GetType().Name,
                UserId      = customerId,
                UserName    = customerName
            })
                                          .Distinct(usageComparer);

            return(new CouponUsageRecordJobArgument()
            {
                OrderId = objectId, PromotionUsages = result.ToArray()
            });
        }
コード例 #2
0
        private List <PromotionUsage> GetCouponUsages(string objectId, IHasDiscounts hasDiscounts, string customerId, string customerName)
        {
            var usageComparer = AnonymousComparer.Create((PromotionUsage x) => string.Join(":", x.PromotionId, x.CouponCode, x.ObjectId));
            var result        = hasDiscounts.GetFlatObjectsListWithInterface <IHasDiscounts>()
                                .Where(x => x.Discounts != null)
                                .SelectMany(x => x.Discounts)
                                .Where(x => !string.IsNullOrEmpty(x.Coupon))
                                .Select(x => new PromotionUsage
            {
                CouponCode  = x.Coupon,
                PromotionId = x.PromotionId,
                ObjectId    = objectId,
                ObjectType  = hasDiscounts.GetType().Name,
                UserId      = customerId,
                UserName    = customerName
            })
                                .Distinct(usageComparer)
                                .ToList();

            return(result);
        }