예제 #1
0
        private void RecordUsages(string objectId, IEnumerable <PromotionUsage> oldUsages, IEnumerable <PromotionUsage> newUsages)
        {
            var toAddUsages    = newUsages.Except(oldUsages, EqualityComparer);
            var toRemoveUsages = oldUsages.Except(newUsages, EqualityComparer);

            if (!toAddUsages.IsNullOrEmpty())
            {
                _usageService.SaveUsages(toAddUsages.ToArray());
            }
            if (!toRemoveUsages.IsNullOrEmpty())
            {
                var alreadyExistUsages = _usageService.SearchUsages(new PromotionUsageSearchCriteria {
                    ObjectId = objectId
                }).Results;
                _usageService.DeleteUsages(alreadyExistUsages.Intersect(toRemoveUsages, EqualityComparer).Select(x => x.Id).ToArray());
            }
        }
        public void DoImport(Stream backupStream, Action <ExportImportProgressInfo> progressCallback)
        {
            var backupObject   = backupStream.DeserializeJson <BackupObject>();
            var originalObject = GetBackupObject(progressCallback);

            var progressInfo = new ExportImportProgressInfo();

            progressInfo.Description = String.Format("{0} promotions importing...", backupObject.Promotions.Count());
            progressCallback(progressInfo);
            _promotionService.SavePromotions(backupObject.Promotions.ToArray());

            progressInfo.Description = String.Format("{0} folders importing...", backupObject.ContentFolders.Count());
            progressCallback(progressInfo);
            _dynamicContentService.SaveFolders(backupObject.ContentFolders.ToArray());

            progressInfo.Description = String.Format("{0} places importing...", backupObject.ContentPlaces.Count());
            progressCallback(progressInfo);
            _dynamicContentService.SavePlaces(backupObject.ContentPlaces.ToArray());

            progressInfo.Description = String.Format("{0} contents importing...", backupObject.ContentItems.Count());
            progressCallback(progressInfo);
            _dynamicContentService.SaveContentItems(backupObject.ContentItems.ToArray());

            progressInfo.Description = String.Format("{0} publications importing...", backupObject.ContentPublications.Distinct().Count());
            progressCallback(progressInfo);
            _dynamicContentService.SavePublications(backupObject.ContentPublications.Distinct().ToArray());

            var pageSize     = 500;
            var couponsTotal = backupObject.Coupons.Count();

            Paginate(couponsTotal, pageSize, (x) =>
            {
                progressInfo.Description = String.Format($"{Math.Min(x * pageSize, couponsTotal)} of {couponsTotal} coupons imported");
                progressCallback(progressInfo);
                _couponService.SaveCoupons(backupObject.Coupons.Skip((x - 1) * pageSize).Take(pageSize).ToArray());
            });

            var usagesTotal = backupObject.Usages.Count();

            Paginate(usagesTotal, pageSize, (x) =>
            {
                progressInfo.Description = String.Format($"{Math.Min(x * pageSize, usagesTotal)} of {usagesTotal} usages imported");
                progressCallback(progressInfo);
                _usageService.SaveUsages(backupObject.Usages.Skip((x - 1) * pageSize).Take(pageSize).ToArray());
            });
        }
 protected virtual void SaveUsages(PromotionUsage[] promotionUsages)
 {
     _usageService.SaveUsages(promotionUsages);
 }