Exemple #1
0
        public async Task DoImportAsync(Stream backupStream, Action <ExportImportProgressInfo> progressCallback,
                                        ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo("Preparing for import");

            progressCallback(progressInfo);

            using (var streamReader = new StreamReader(backupStream, Encoding.UTF8))
                using (var jsonReader = new JsonTextReader(streamReader))
                {
                    while (jsonReader.Read())
                    {
                        if (jsonReader.TokenType == JsonToken.PropertyName)
                        {
                            if (jsonReader.Value.ToString() == "PaymentPlans" &&
                                TryReadCollectionOf <PaymentPlan>(jsonReader, out var paymentPlans))
                            {
                                var totalCount = paymentPlans.Count;
                                for (int skip = 0; skip < totalCount; skip += BatchSize)
                                {
                                    var currentPaymentPlans = paymentPlans.Skip(skip).Take(BatchSize).ToArray();
                                    await _paymentPlanService.SavePlansAsync(currentPaymentPlans);

                                    progressInfo.Description = $"{Math.Min(skip + BatchSize, totalCount)} of {totalCount} payment plans have been imported.";
                                    progressCallback(progressInfo);
                                }
                            }
                            else if (jsonReader.Value.ToString() == "Subscriptions" &&
                                     TryReadCollectionOf <Subscription>(jsonReader, out var subscriptions))
                            {
                                var totalCount = subscriptions.Count;
                                for (int skip = 0; skip < totalCount; skip += BatchSize)
                                {
                                    var currentSubscriptions = subscriptions.Skip(skip).Take(BatchSize).ToArray();
                                    await _subscriptionService.SaveSubscriptionsAsync(currentSubscriptions);

                                    progressInfo.Description = $"{Math.Min(skip + BatchSize, totalCount)} of {totalCount} subscriptions have been imported.";
                                    progressCallback(progressInfo);
                                }
                            }
                        }
                    }
                }
        }
Exemple #2
0
        public async Task <IActionResult> CreatePaymentPlan([FromBody] PaymentPlan plan)
        {
            await _planService.SavePlansAsync(new[] { plan });

            return(Ok(plan));
        }