private async Task <bool> UpdateCategoryIfAlreadyExistsInOtherAffiliateProgram( IList <Category> existingCategorys, IList <AffiliateCategoryMatch> existingMatches, AffiliateCategory affiliateCategory) { if (existingCategorys == null || !existingCategorys.Any()) { return(false); } if (existingMatches == null || !existingMatches.Any()) { return(false); } var categoryToUpdate = existingCategorys.FirstOrDefault(category => category.IsMatchableName(affiliateCategory.Name)); if (categoryToUpdate == null) { return(false); } var newMatch = AffiliateCategoryMatch.Create(categoryToUpdate, affiliateCategory); await _matchesRepository.SaveAsync(newMatch); UpdateCategoryProperties(categoryToUpdate, affiliateCategory, existingMatches); await _categoryRepository.SaveAsync(categoryToUpdate); return(true); }
private async Task CreateCategoryAndMatch(AffiliateCategory affiliateCategory) { var categoryToCreate = Category.Create(); UpdateCategoryProperties(categoryToCreate, affiliateCategory); await _categoryRepository.SaveAsync(categoryToCreate); var newMatch = AffiliateCategoryMatch.Create(categoryToCreate, affiliateCategory); await _matchesRepository.SaveAsync(newMatch); }
public void Update(AffiliateCategoryMatch categoryMatch) { if (categoryMatch == null) { throw new ArgumentNullException(nameof(categoryMatch)); } if (Matched(categoryMatch)) { CouponsCount = categoryMatch.CouponsCount; } }
public bool Matched(AffiliateCategoryMatch affiliateCategory) { return(affiliateCategory != null && affiliateCategory.AffiliateCategoryId == AffiliateCategoryId && affiliateCategory.AffiliateProgram == AffiliateProgram); }