private void ClearCache(string[] promotionIds = null) { CouponCacheRegion.ExpireRegion(); PromotionSearchCacheRegion.ExpireRegion(); if (promotionIds != null) { PromotionCacheRegion.ExpirePromotions(promotionIds); } }
public async Task DeleteCouponsAsync(string[] ids) { using (var repository = _repositoryFactory()) { await repository.RemoveCouponsAsync(ids); await repository.UnitOfWork.CommitAsync(); } CouponCacheRegion.ExpireRegion(); }
public async Task SaveCouponsAsync(Coupon[] coupons) { var pkMap = new PrimaryKeyResolvingMap(); var changedEntries = new List <GenericChangedEntry <Coupon> >(); using (var repository = _repositoryFactory()) { var existCouponEntities = await repository.GetCouponsByIdsAsync(coupons.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray()); foreach (var coupon in coupons) { var sourceEntity = AbstractTypeFactory <CouponEntity> .TryCreateInstance(); if (sourceEntity != null) { sourceEntity = sourceEntity.FromModel(coupon, pkMap); var targetCouponEntity = existCouponEntities.FirstOrDefault(x => x.Id == coupon.Id); if (targetCouponEntity != null) { changedEntries.Add(new GenericChangedEntry <Coupon>(coupon, sourceEntity.ToModel(AbstractTypeFactory <Coupon> .TryCreateInstance()), EntryState.Modified)); sourceEntity.Patch(targetCouponEntity); } else { changedEntries.Add(new GenericChangedEntry <Coupon>(coupon, EntryState.Added)); repository.Add(sourceEntity); } } } await repository.UnitOfWork.CommitAsync(); pkMap.ResolvePrimaryKeys(); await _eventPublisher.Publish(new CouponChangedEvent(changedEntries)); } CouponCacheRegion.ExpireRegion(); }