public void Process() { var criteria = new SubscriptionSearchCriteria { Statuses = new[] { SubscriptionStatus.Active, SubscriptionStatus.PastDue, SubscriptionStatus.Trialing, SubscriptionStatus.Unpaid }.Select(x => x.ToString()).ToArray(), Take = 0, }; var result = _subscriptionSearchService.SearchSubscriptions(criteria); var batchSize = 20; for (var i = 0; i < result.TotalCount; i += batchSize) { criteria.Skip = i; criteria.Take = batchSize; result = _subscriptionSearchService.SearchSubscriptions(criteria); var subscriptions = _subscriptionService.GetByIds(result.Results.Select(x => x.Id).ToArray()); foreach (var subscription in subscriptions) { var newOrder = _subscriptionBuilder.TakeSubscription(subscription).Actualize().TryToCreateRecurrentOrder(); if (newOrder != null) { _customerOrderService.SaveChanges(new[] { newOrder }); } } } }
public IHttpActionResult SearchSubscriptions(SubscriptionSearchCriteria criteria) { var result = _subscriptionSearchService.SearchSubscriptions(criteria); var retVal = new SubscriptionSearchResult { Subscriptions = result.Results.ToList(), TotalCount = result.TotalCount }; return(Ok(retVal)); }
private BackupObject GetBackupObject(Action <ExportImportProgressInfo> progressCallback) { var retVal = new BackupObject(); var progressInfo = new ExportImportProgressInfo(); var take = 20; var searchResponse = _subscriptionSearchService.SearchSubscriptions(new SubscriptionSearchCriteria { Take = 0, ResponseGroup = SubscriptionResponseGroup.Default.ToString() }); for (int skip = 0; skip < searchResponse.TotalCount; skip += take) { searchResponse = _subscriptionSearchService.SearchSubscriptions(new SubscriptionSearchCriteria { Skip = skip, Take = take, ResponseGroup = SubscriptionResponseGroup.Default.ToString() }); progressInfo.Description = String.Format("{0} of {1} subscriptions loading", Math.Min(skip + take, searchResponse.TotalCount), searchResponse.TotalCount); progressCallback(progressInfo); retVal.Subscriptions.AddRange(searchResponse.Results); } var paymentPlanSearchResponse = _paymentPlanSearchService.SearchPlans(new PaymentPlanSearchCriteria { Take = 0 }); for (int skip = 0; skip < paymentPlanSearchResponse.TotalCount; skip += take) { paymentPlanSearchResponse = _paymentPlanSearchService.SearchPlans(new PaymentPlanSearchCriteria { Skip = skip, Take = take }); progressInfo.Description = String.Format("{0} of {1} payment plans loading", Math.Min(skip + take, paymentPlanSearchResponse.TotalCount), paymentPlanSearchResponse.TotalCount); progressCallback(progressInfo); retVal.PaymentPlans.AddRange(paymentPlanSearchResponse.Results); } return(retVal); }
public void Process() { var criteria = new SubscriptionSearchCriteria { Statuses = new[] { SubscriptionStatus.Active, SubscriptionStatus.PastDue, SubscriptionStatus.Trialing, SubscriptionStatus.Unpaid }.Select(x => x.ToString()).ToArray(), Take = 0 }; var result = _subscriptionSearchService.SearchSubscriptions(criteria); var batchSize = 20; for (var i = 0; i < result.TotalCount; i += batchSize) { criteria.Skip = i; criteria.Take = batchSize; result = _subscriptionSearchService.SearchSubscriptions(criteria); var subscriptions = _subscriptionService.GetByIds(result.Results.Select(x => x.Id).ToArray()); foreach (var subscription in subscriptions) { _subscriptionBuilder.TakeSubscription(subscription).Actualize(); } _subscriptionService.SaveSubscriptions(subscriptions); } }