Ejemplo n.º 1
0
        public async Task ProcessUnifiedStore(AffiliateStore affiliateStore)
        {
            if (affiliateStore == null)
            {
                throw new ArgumentNullException(nameof(affiliateStore));
            }

            var matchedIds = await _matchesRepository.GetAllAsync();

            var stores = await _storeRepository.GetAllAsync();

            var updated = await UpdateStoreIfAlreadyExistsInTheSameAffiliateProgram(stores, matchedIds, affiliateStore);

            if (updated)
            {
                return;
            }

            updated = await UpdateStoreIfAlreadyExistsInOtherAffiliateProgram(stores, matchedIds, affiliateStore);

            if (updated)
            {
                return;
            }

            await CreateStoreAndMatch(affiliateStore);
        }
Ejemplo n.º 2
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);
        }