Exemplo n.º 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()
            });
        }
Exemplo n.º 2
0
        private List <PromotionUsage> GetCouponUsages(string objectId, IHasDiscounts hasDiscounts)
        {
            var usageComparer = AnonymousComparer.Create((PromotionUsage x) => string.Join(":", x.PromotionId, x.CouponCode, x.ObjectId));
            var retVal        = 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
            })
                                .Distinct(usageComparer)
                                .ToList();

            return(retVal);
        }