コード例 #1
0
        public static AffiliateCouponMatch Create(Coupon coupon, AffiliateCoupon affiliateCoupon)
        {
            var match = affiliateCoupon.GetAdvertiseId();

            match.AdvertiseCouponId = coupon.CouponId;
            return(match);
        }
コード例 #2
0
 public static AffiliateCouponMatch GetAdvertiseId(this AffiliateCoupon affiliateCoupon)
 {
     return(new AffiliateCouponMatch
     {
         Id = Guid.NewGuid(),
         AffiliateCouponId = affiliateCoupon.CouponId,
         AffiliateProgram = affiliateCoupon.AffiliateProgram
     });
 }
コード例 #3
0
        private static void UpdateProperties(Coupon coupon,
                                             AffiliateCoupon affiliateCoupon,
                                             IList <AffiliateStoreMatch> storesMatches,
                                             IList <AffiliateCategoryMatch> categoriesMatches,
                                             bool isNew = true)
        {
            coupon.ChangedDate = DateTime.UtcNow;
            coupon.Code        = affiliateCoupon.Code;
            coupon.CouponLink  = affiliateCoupon.CouponLink;
            if (isNew)
            {
                coupon.Description         = affiliateCoupon.Description;
                coupon.Discount            = affiliateCoupon.Discount;
                coupon.FriendlyDescription = affiliateCoupon.FriendlyDescription;
                coupon.IsPercentage        = affiliateCoupon.IsPercentage;
                coupon.Remark = affiliateCoupon.Remark;
            }
            coupon.New      = affiliateCoupon.New;
            coupon.Shipping = affiliateCoupon.Shipping;
            coupon.Validity = affiliateCoupon.Validity.ToUniversalTime();

            var matchedCategory = categoriesMatches?.FirstOrDefault(matched =>
                                                                    matched.AffiliateProgram == affiliateCoupon.AffiliateProgram &&
                                                                    matched.AffiliateCategoryId == affiliateCoupon.Category.Id);

            coupon.Category = (affiliateCoupon.Category == null || matchedCategory == null)
                ? Category.GetDefaultCategory()
                : new Category
            {
                Id           = matchedCategory.AdvertiseCategoryId.ToString(),
                Name         = affiliateCoupon.Category.Name,
                FriendlyName = affiliateCoupon.Category.FriendlyName
            };

            var matchedStore = storesMatches?.FirstOrDefault(matched =>
                                                             matched.AffiliateProgram == affiliateCoupon.AffiliateProgram &&
                                                             matched.AffiliateStoreId == affiliateCoupon.Store.Id);

            coupon.Store = (affiliateCoupon.Store == null || matchedStore == null)
                ? Store.GetDefaultStore()
                : new Store
            {
                Id           = matchedStore.AdvertiseStoreId.ToString(),
                Name         = affiliateCoupon.Store.Name,
                FriendlyName = affiliateCoupon.Store.FriendlyName,
                StoreUrl     = affiliateCoupon.Store.StoreUrl,
                ImageUrl     = affiliateCoupon.Store.ImageUrl
            };
        }
コード例 #4
0
 protected bool Equals(AffiliateCoupon other)
 {
     return(CouponId == other.CouponId &&
            AffiliateProgram == other.AffiliateProgram &&
            Description == other.Description &&
            FriendlyDescription == other.FriendlyDescription &&
            Remark == other.Remark &&
            Code == other.Code &&
            Discount == other.Discount &&
            Equals(Store, other.Store) &&
            Equals(Category, other.Category) &&
            Validity.Equals(other.Validity) &&
            Equals(CouponLink, other.CouponLink) &&
            New == other.New &&
            IsPercentage == other.IsPercentage &&
            Shipping == other.Shipping);
 }
コード例 #5
0
        public async Task ProcessCoupon(AffiliateCoupon affiliateCoupon)
        {
            if (affiliateCoupon == null)
            {
                throw new ArgumentNullException(nameof(affiliateCoupon));
            }

            var couponsMatches = await _matchesRepository.GetAllAsync();

            var categoriesMatches = await _categoryRepository.GetAllAsync();

            var storesMatches = await _storeRepository.GetAllAsync();

            var matchedCoupon = couponsMatches.FirstOrDefault(matched =>
                                                              matched.AffiliateProgram == affiliateCoupon.AffiliateProgram &&
                                                              matched.AffiliateCouponId == affiliateCoupon.CouponId);

            if (matchedCoupon != null)
            {
                var coupons = await _couponRepository.GetAllAsync();

                var couponToChange = coupons.FirstOrDefault(c => c.CouponId == matchedCoupon.AdvertiseCouponId);
                UpdateProperties(couponToChange, affiliateCoupon, storesMatches, categoriesMatches, false);
                await _couponRepository.SaveAsync(couponToChange);

                return;
            }

            var newCoupon = Coupon.Create();

            UpdateProperties(newCoupon, affiliateCoupon, storesMatches, categoriesMatches);
            matchedCoupon = AffiliateCouponMatch.Create(newCoupon, affiliateCoupon);
            await _matchesRepository.SaveAsync(matchedCoupon);

            await _couponRepository.SaveAsync(newCoupon);
        }
コード例 #6
0
 public void CancelCoupon(AffiliateCoupon affiliateCoupon)
 {
 }