Beispiel #1
0
        public static AffiliateCategoryMatch Create(Category category, AffiliateCategory affiliateCategory)
        {
            var match = affiliateCategory.GetAdvertiseId();

            match.AdvertiseCategoryId = category.CategoryId;
            return(match);
        }
Beispiel #2
0
        private static void UpdateCategoryProperties(Category category, AffiliateCategory affiliateCategory, IList <AffiliateCategoryMatch> allMatches = null)
        {
            var advertiseId = affiliateCategory.GetAdvertiseId();

            category.Name         = affiliateCategory.Name;
            category.FriendlyName = affiliateCategory.FriendlyName;
            category.CategoryUrl  = affiliateCategory.CategoryUrl;
            category.ChangedDate  = affiliateCategory.ChangedDate;
            if (allMatches == null || !allMatches.Any())
            {
                category.CouponsCount = affiliateCategory.CouponsCount;
            }
            else
            {
                category.CouponsCount = allMatches.Where(m => m.AdvertiseCategoryId == category.CategoryId).Sum(m => m.CouponsCount);
            }
        }
Beispiel #3
0
        private async Task <bool> UpdateCategoryIfAlreadyExistsInTheSameAffiliateProgram(
            IList <Category> existingCategorys,
            IList <AffiliateCategoryMatch> existingMatches,
            AffiliateCategory affiliateCategory)
        {
            if (existingCategorys == null || !existingCategorys.Any())
            {
                return(false);
            }
            if (existingMatches == null || !existingMatches.Any())
            {
                return(false);
            }

            var advertiseId   = affiliateCategory.GetAdvertiseId();
            var previousMatch = existingMatches.FirstOrDefault(id => id.Matched(advertiseId));

            if (previousMatch == null)
            {
                return(false);
            }

            var foundCategory = existingCategorys.FirstOrDefault(category => category.CategoryId == previousMatch.AdvertiseCategoryId);

            if (foundCategory == null)
            {
                return(false);
            }

            // Update match
            previousMatch.Update(advertiseId);
            await _matchesRepository.SaveAsync(previousMatch);

            // Update category
            UpdateCategoryProperties(foundCategory, affiliateCategory, existingMatches);
            await _categoryRepository.SaveAsync(foundCategory);

            return(true);
        }