public async Task <IActionResult> PublishYourFile(ApprenticeshipsPublishYourFileViewModel model)
        {
            int?sUKPRN = HttpContext.Session.GetInt32("UKPRN");
            int UKPRN;

            if (!sUKPRN.HasValue)
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Please select a Provider." }));
            }

            UKPRN = sUKPRN ?? 0;


            var resultArchivingApprenticeships = await _apprenticeshipService.ChangeApprenticeshipStatusesForUKPRNSelection(
                UKPRN,
                (int)(RecordStatus.Live | RecordStatus.MigrationPending | RecordStatus.Pending | RecordStatus.MigrationReadyToGoLive),
                (int)RecordStatus.Archived);

            if (!resultArchivingApprenticeships.IsSuccess)
            {
                throw new Exception(resultArchivingApprenticeships.Error);
            }

            await _apprenticeshipService.ChangeApprenticeshipStatusesForUKPRNSelection(UKPRN, (int)RecordStatus.BulkUploadReadyToGoLive, (int)RecordStatus.Live);

            //to publish stuff
            return(View("../BulkUploadApprenticeships/Complete/Index", new ApprenticeshipsPublishCompleteViewModel()
            {
                NumberOfApprenticeshipsPublished = model.NumberOfApprenticeships, Mode = PublishMode.ApprenticeshipBulkUpload
            }));
        }
        public async Task <IActionResult> Index(PublishApprenticeshipsViewModel vm)
        {
            PublishCompleteViewModel CompleteVM = new PublishCompleteViewModel();

            int?sUKPRN = Session.GetInt32("UKPRN");
            int UKPRN;

            if (!sUKPRN.HasValue)
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Please select a Provider." }));
            }
            else
            {
                UKPRN = sUKPRN ?? 0;
            }

            CompleteVM.NumberOfCoursesPublished = vm.NumberOfApprenticeships;
            await _apprenticeshipService.ChangeApprenticeshipStatusesForUKPRNSelection(UKPRN, (int)RecordStatus.MigrationPending, (int)RecordStatus.Archived);

            await _apprenticeshipService.ChangeApprenticeshipStatusesForUKPRNSelection(UKPRN, (int)RecordStatus.MigrationReadyToGoLive, (int)RecordStatus.Archived);

            //Archive any existing courses
            var resultArchivingCourses = await _apprenticeshipService.ChangeApprenticeshipStatusesForUKPRNSelection(UKPRN, (int)RecordStatus.Live, (int)RecordStatus.Archived);

            if (resultArchivingCourses.IsSuccess)
            {
                // Publish courses
                var resultPublishBulkUploadedCourses = await _apprenticeshipService.ChangeApprenticeshipStatusesForUKPRNSelection(UKPRN, (int)RecordStatus.BulkUploadReadyToGoLive, (int)RecordStatus.Live);

                CompleteVM.Mode = PublishMode.BulkUpload;
                if (resultPublishBulkUploadedCourses.IsSuccess)
                {
                    return(RedirectToAction("Complete", "Apprenticeships", new { CompleteVM }));
                }
                else
                {
                    return(RedirectToAction("Index", "Home", new { errmsg = "Publish All BulkUpload-PublishCourses Error" }));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Publish All BulkUpload-ArchiveCourses Error" }));
            }
        }