Esempio n. 1
0
        public async Task UpdateReport(int ukprn)
        {
            using (var client = _cosmosDbHelper.GetClient())
            {
                var courses = await _cosmosDbHelper.GetCourseCollectionDocumentsByUKPRN <Course>(client, _settings.CoursesCollectionId,
                                                                                                 ukprn);

                var migrationReport = (await _cosmosDbHelper.GetCourseCollectionDocumentsByUKPRN <CourseMigrationReport>(client,
                                                                                                                         _settings.CoursesMigrationReportCollectionId,
                                                                                                                         ukprn)).FirstOrDefault();
                var provider = await _cosmosDbHelper.GetProviderByUKPRN(client, _settings.ProviderCollectionId,
                                                                        ukprn);


                if (provider == null || !HasValidReportOrCourses(courses, migrationReport))
                {
                    throw new Exception($"Unable to generate report for Provider: {ukprn}");
                }

                var report = new CourseReportDocument
                {
                    ProviderUKPRN                = ukprn.ToString(),
                    MigrationPendingCount        = courses.SelectMany(x => x.CourseRuns.Where(cr => cr.RecordStatus == RecordStatus.MigrationPending)).Count(),
                    MigrationReadyToGoLive       = courses.SelectMany(x => x.CourseRuns.Where(cr => cr.RecordStatus == RecordStatus.MigrationReadyToGoLive)).Count(),
                    BulkUploadPendingcount       = courses.SelectMany(x => x.CourseRuns.Where(cr => cr.RecordStatus == RecordStatus.BulkUloadPending)).Count(),
                    BulkUploadReadyToGoLiveCount = courses.SelectMany(x => x.CourseRuns.Where(cr => cr.RecordStatus == RecordStatus.BulkUploadReadyToGoLive)).Count(),
                    FailedMigrationCount         = migrationReport?.LarslessCourses?.SelectMany(cr => cr.CourseRuns)?.Count(),
                    LiveCount     = courses.SelectMany(c => c.CourseRuns.Where(cr => cr.RecordStatus == RecordStatus.Live)).Count(),
                    MigratedCount = migrationReport?.PreviousLiveCourseCount,
                    MigrationDate = migrationReport?.Timestamp,
                    MigrationRate = decimal.Round(MigrationRate(courses), 2, MidpointRounding.AwayFromZero),
                    ProviderName  = provider.ProviderName,
                    ProviderType  = provider.ProviderType
                };

                await _cosmosDbHelper.UpdateDocumentAsync(client, _settings.DfcReportCollectionId, report);
            }
        }
Esempio n. 2
0
        public async Task UpdateReport(int ukprn)
        {
            using (var client = _cosmosDbHelper.GetClient())
            {
                var apprenticeships = await _cosmosDbHelper.GetCourseCollectionDocumentsByUKPRN <Apprenticeship>(client, _settings.ApprenticeshipCollectionId,
                                                                                                                 ukprn);

                var migrationReport = (await _cosmosDbHelper.GetCourseCollectionDocumentsByUKPRN <ApprenticeshipMigrationReport>(client,
                                                                                                                                 _settings.ApprenticeshipMigrationReportCollectionId,
                                                                                                                                 ukprn)).FirstOrDefault();
                var provider = await _cosmosDbHelper.GetProviderByUKPRN(client, _settings.ProviderCollectionId,
                                                                        ukprn);


                if (provider == null || !HasValidReportOrApprenticeships(apprenticeships, migrationReport))
                {
                    throw new Exception($"Unable to generate report for Provider: {ukprn}");
                }

                var report = new ApprenticeshipDfcReportDocument()
                {
                    ProviderUKPRN                = ukprn.ToString(),
                    MigrationPendingCount        = apprenticeships.SelectMany(x => x.ApprenticeshipLocations.Where(cr => cr.RecordStatus == RecordStatus.MigrationPending)).Count(),
                    MigrationReadyToGoLive       = apprenticeships.SelectMany(x => x.ApprenticeshipLocations.Where(cr => cr.RecordStatus == RecordStatus.MigrationReadyToGoLive)).Count(),
                    BulkUploadPendingcount       = apprenticeships.SelectMany(x => x.ApprenticeshipLocations.Where(cr => cr.RecordStatus == RecordStatus.BulkUloadPending)).Count(),
                    BulkUploadReadyToGoLiveCount = apprenticeships.SelectMany(x => x.ApprenticeshipLocations.Where(cr => cr.RecordStatus == RecordStatus.BulkUploadReadyToGoLive)).Count(),
                    FailedMigrationCount         = migrationReport?.NotTransferred,
                    LiveCount     = apprenticeships.SelectMany(c => c.ApprenticeshipLocations.Where(cr => cr.RecordStatus == RecordStatus.Live)).Count(),
                    MigratedCount = migrationReport?.ApprenticeshipsMigrated,
                    MigrationDate = migrationReport?.MigrationDate,
                    MigrationRate = decimal.Round(MigrationRate(apprenticeships), 2, MidpointRounding.AwayFromZero),
                    ProviderName  = provider.ProviderName,
                    ProviderType  = provider.ProviderType
                };

                await _cosmosDbHelper.UpdateDocumentAsync(client, _settings.ApprenticeshipDfcReportCollection, report);
            }
        }