Beispiel #1
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)]
                                                     HttpRequestMessage req,
                                                     ILogger log,
                                                     [Inject] IApprenticeshipService coursesService)
        {
            log.LogInformation($"DeleteCoursesByUKPRN starting");

            string strUKPRN = req.RequestUri.ParseQueryString()["UKPRN"]?.ToString()
                              ?? (await(dynamic) req.Content.ReadAsAsync <object>())?.UKPRN;

            List <string> messagesList = null;

            if (string.IsNullOrWhiteSpace(strUKPRN))
            {
                return(new BadRequestObjectResult($"Empty or missing UKPRN value."));
            }

            if (!int.TryParse(strUKPRN, out int UKPRN))
            {
                return(new BadRequestObjectResult($"Invalid UKPRN value, expected a valid integer"));
            }

            try
            {
                messagesList = await coursesService.DeleteBulkUploadApprenticeships(UKPRN);

                await coursesService.ChangeApprenticeshipStatusForUKPRNSelection(UKPRN, RecordStatus.MigrationPending,
                                                                                 RecordStatus.Archived);

                await coursesService.ChangeApprenticeshipStatusForUKPRNSelection(UKPRN,
                                                                                 RecordStatus.MigrationReadyToGoLive, RecordStatus.Archived);

                if (messagesList == null)
                {
                    return(new NotFoundObjectResult(UKPRN));
                }

                return(new OkObjectResult(messagesList));
            }
            catch (Exception e)
            {
                return(new InternalServerErrorObjectResult(e));
            }
        }
        public async Task <IActionResult> DeleteFile(DeleteFileViewModel model)
        {
            DateTimeOffset fileUploadDate = new DateTimeOffset();
            int?           sUKPRN         = HttpContext.Session.GetInt32("UKPRN");
            int            UKPRN;

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

            IEnumerable <Services.BlobStorageService.BlobFileInfo> list = _blobService.GetFileList(UKPRN + _blobContainerPath).OrderByDescending(x => x.DateUploaded).ToList();

            if (list.Any())
            {
                TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
                DateTime     dt1 = DateTime.Parse(list.FirstOrDefault().DateUploaded.Value.DateTime.ToString());
                DateTime     dt2 = TimeZoneInfo.ConvertTimeFromUtc(dt1, tzi);

                fileUploadDate = Convert.ToDateTime(dt2.ToString("dd MMM yyyy HH:mm"));;
                var archiveFilesResult = _blobService.ArchiveFiles($"{UKPRN.ToString()}{_blobContainerPath}");
            }

            var deleteBulkuploadResults = await _apprenticeshipService.DeleteBulkUploadApprenticeships(UKPRN);

            if (deleteBulkuploadResults.IsSuccess)
            {
                return(RedirectToAction("DeleteFileConfirmation", "BulkUploadApprenticeships", new { fileUploadDate = fileUploadDate }));
            }
            else
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Delete All Bulk Uploaded Apprenticeships Error" }));
            }
        }