Exemple #1
0
        public async Task <IActionResult> Index()
        {
            var ukPRN = Session.GetInt32("UKPRN");

            if (ukPRN != null)
            {
                Session.Remove("UKPRN");
            }

            string dateLastUpdate;
            MigrationReportViewModel2 model = new MigrationReportViewModel2();

            // Get courses data
            var couresesReportResultsTask = _courseService.GetAllDfcReports();
            var appsReportResultsTask     = _apprenticeshipService.GetAllDfcReports();
            await Task.WhenAll(couresesReportResultsTask, appsReportResultsTask);

            var courseReportResults = couresesReportResultsTask.Result;
            var appsReportResults   = appsReportResultsTask.Result;

            if (!courseReportResults.IsSuccess)
            {
                throw new Exception("Unable to generate migration reports");
            }

            var courseReportData = courseReportResults.Value.Where(c => c.CreatedBy == appName); // Only show records that have been updated by report migrator
            var appReportData    = appsReportResults.Value.Where(c => c.CreatedBy == appName);   // Only show records that have been updated by report migrator

            // Get providers in both reports
            var providersInBoth = from c in courseReportData
                                  join a in appReportData
                                  on c.ProviderUKPRN equals a.ProviderUKPRN
                                  select c.ProviderUKPRN;

            // Get providers in  courses reports only
            var providersInCoursesOnly = from c in courseReportData
                                         where !providersInBoth.Contains(c.ProviderUKPRN)
                                         select c.ProviderUKPRN;

            // Get providers in  apps reports only
            var providersInAppsOnly = from a in appReportData
                                      where !providersInBoth.Contains(a.ProviderUKPRN)
                                      select a.ProviderUKPRN;


            int totalProvidersMigrated = providersInBoth.Count()
                                         + providersInCoursesOnly.Count()
                                         + providersInAppsOnly.Count();

            dateLastUpdate = appReportData.First().CreatedOn.ToString("dd/MM/yyyy H:mm");

            // Perform course calculations
            var feCoursesPendingCount  = courseReportData.Sum(r => r.MigrationPendingCount);
            var feCoursesLiveCount     = courseReportData.Sum(r => r.LiveCount);
            int feCoursesMigratedCount = courseReportData.Sum(r => r.MigratedCount) ?? 0;

            // Perform apps calculations
            int appsPendingCount  = appReportData.Sum(r => r.MigrationPendingCount);
            int appsLiveCount     = appReportData.Sum(r => r.LiveCount);
            int appsMigratedCount = appReportData.Sum(r => r.MigratedCount) ?? 0;

            model.TotalProvidersMigrated = new MigrationReportDashboardPanelModel("Total providers migrated", value: totalProvidersMigrated);
            model.DateLastUpdated        = dateLastUpdate;

            model.CoursesMigrated     = new MigrationReportDashboardPanelModel("Migrated", value: feCoursesMigratedCount);
            model.CoursesPending      = new MigrationReportDashboardPanelModel("Pending", value: feCoursesPendingCount);
            model.CoursesLive         = new MigrationReportDashboardPanelModel("Live", value: feCoursesLiveCount);
            model.CourseReportResults = new MigrationReportResultsModel(new List <DfcMigrationReport>());

            model.ApprenticeshipMigrated      = new MigrationReportDashboardPanelModel("Migrated", value: appsMigratedCount);
            model.ApprenticeshipPending       = new MigrationReportDashboardPanelModel("Pending", value: appsPendingCount);
            model.ApprenticeshipLive          = new MigrationReportDashboardPanelModel("Live", value: appsLiveCount);
            model.ApprenticeshipReportResults = new MigrationReportResultsModel(new List <DfcMigrationReport>());

            return(View(model));
        }