Exemplo n.º 1
0
        public async Task <IActionResult> DeleteFile(DeleteFileViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(cuser, 3);
                return(View(model));
            }
            var fileinfo = await ApiService.ViewOneFileAsync(model.FileId);

            var bucketInfo = await ApiService.ViewBucketDetailAsync(fileinfo.File.BucketId);

            var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId);

            if (fileinfo == null || bucketInfo.BelongingAppId != app.AppId || fileinfo.File.BucketId != bucketInfo.BucketId)
            {
                return(Unauthorized());
            }
            await ApiService.DeleteFileAsync(await AppsContainer.AccessToken(app.AppId, app.AppSecret)(), model.FileId, bucketInfo.BucketId);

            return(RedirectToAction(nameof(ViewFiles), new
            {
                id = bucketInfo.BucketId
            }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeleteFile(DeleteFileViewModel model)
        {
            var user = await GetCurrentUserAsync();

            var app = await _dbContext.Apps.FindAsync(model.AppId);

            if (app == null)
            {
                return(NotFound());
            }
            if (app.CreatorId != user.Id)
            {
                return(Unauthorized());
            }
            if (!ModelState.IsValid)
            {
                model.Recover(user, app.AppName);
                return(View(model));
            }
            try
            {
                var token = await _appsContainer.AccessToken(app.AppId, app.AppSecret);

                await _filesService.DeleteFileAsync(token, model.SiteName, model.Path);

                return(RedirectToAction(nameof(ViewFiles), new { appId = model.AppId, siteName = model.SiteName, path = model.Path.DetachPath() }));
            }
            catch (AiurUnexpectedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.Recover(user, app.AppName);
                return(View(model));
            }
        }
        public IActionResult DeleteFile()
        {
            var model = new DeleteFileViewModel();


            return(View("../Bulkupload/DeleteFile/Index", model));
        }
Exemplo n.º 4
0
        public void DeleteFile(DeleteFileViewModel model)
        {
            var dirname         = model.Folder;
            var contentRootPath = _hostingEnvironment.ContentRootPath;
            var dirPath         = Path.Combine(contentRootPath, "wwwroot", "uploads", dirname);
            var path            = Path.Combine(dirPath, model.FileName);

            File.Delete(path);
        }
        public async Task <IActionResult> DeleteFile([FromRoute] string path)
        {
            var user = await GetCurrentUserAsync();

            var model = new DeleteFileViewModel(user)
            {
                Path = path
            };

            return(View(model));
        }
Exemplo n.º 6
0
        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 apprenticeships = await _cosmosDbQueryDispatcher.ExecuteQuery(new GetApprenticeships
            {
                Predicate = a =>
                            a.ProviderUKPRN == UKPRN &&
                            (a.RecordStatus == (int)ApprenticeshipStatus.BulkUploadPending || a.RecordStatus == (int)ApprenticeshipStatus.BulkUploadReadyToGoLive)
            });

            foreach (var apprenticeship in apprenticeships.Values)
            {
                await _cosmosDbQueryDispatcher.ExecuteQuery(new DeleteApprenticeship { ApprenticeshipId = apprenticeship.Id, ProviderUkprn = apprenticeship.ProviderUKPRN });
            }

            return(RedirectToAction("DeleteFileConfirmation", "BulkUploadApprenticeships", new { fileUploadDate = fileUploadDate }));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> DeleteFile(DeleteFileViewModel model)
        {
            var UKPRN = _session.GetInt32("UKPRN");

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

            var provider = await _cosmosDbQueryDispatcher.ExecuteQuery(new GetProviderByUkprn { Ukprn = UKPRN.Value });

            if (provider == null)
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Failed to find Provider data to delete bulk upload." }));
            }

            var blobFiles = _blobService.GetFileList(UKPRN + "/Bulk Upload/Files/").OrderByDescending(x => x.DateUploaded).ToList();

            if (blobFiles.Any())
            {
                _blobService.ArchiveFiles($"{UKPRN}/Bulk Upload/Files/");
            }
Exemplo n.º 8
0
        public async Task <IActionResult> DeleteFile(DeleteFileViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(user);
                return(View(model));
            }
            try
            {
                await _filesService.DeleteFileAsync(await AccessToken, user.SiteName, model.Path);

                return(RedirectToAction(nameof(ViewFiles), new { path = model.Path.DetachPath() }));
            }
            catch (AiurUnexpectedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.Recover(user);
                return(View(model));
            }
        }
        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" }));
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> DeleteFile(int id)
        {
            var cuser = await GetCurrentUserAsync();

            var fileinfo = await ApiService.ViewOneFileAsync(id);

            var bucketInfo = await ApiService.ViewBucketDetailAsync(fileinfo.File.BucketId);

            var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId);

            if (bucketInfo.BelongingAppId != app.AppId)
            {
                return(Unauthorized());
            }
            var model = new DeleteFileViewModel(cuser)
            {
                FileName = fileinfo.File.RealFileName,
                FileId   = fileinfo.File.FileKey,
                BucketId = fileinfo.File.BucketId
            };

            return(View(model));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> DeleteFile([FromRoute] string appId, [FromRoute] string siteName, [FromRoute] string path)
        {
            var user = await GetCurrentUserAsync();

            var app = await _dbContext.Apps.FindAsync(appId);

            if (app == null)
            {
                return(NotFound());
            }
            if (app.CreatorId != user.Id)
            {
                return(Unauthorized());
            }
            var model = new DeleteFileViewModel(user)
            {
                AppId    = appId,
                SiteName = siteName,
                Path     = path,
                AppName  = app.AppName
            };

            return(View(model));
        }
        public IActionResult DeleteFile(DeleteFileViewModel model)
        {
            DateTimeOffset fileUploadDate = new DateTimeOffset();
            int?           sUKPRN         = _session.GetInt32("UKPRN");
            int            UKPRN;

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

            var provider = FindProvider(UKPRN);

            if (null == provider)
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Failed to find Provider data to delete bulk upload." }));
            }

            IEnumerable <Services.BlobStorageService.BlobFileInfo> list = _blobService.GetFileList(UKPRN + "/Bulk Upload/Files/").OrderByDescending(x => x.DateUploaded).ToList();

            if (list.Any())
            {
                fileUploadDate = list.FirstOrDefault().DateUploaded.Value;
                var archiveFilesResult = _blobService.ArchiveFiles($"{UKPRN.ToString()}/Bulk Upload/Files/");
            }


            // COUR-1927 move the delete to a background worker because it's timing out for large files.
            bool deleteSuccess = false;

            _queue.QueueBackgroundWorkItem(async token =>
            {
                var guid           = Guid.NewGuid().ToString();
                var tag            = $"delete bulk upload for provider {UKPRN}.";
                var startTimestamp = DateTime.UtcNow;

                try
                {
                    _logger.LogInformation($"{startTimestamp.ToString("yyyyMMddHHmmss")} Starting background worker {guid} for {tag}");

                    var deleteBulkuploadResults = await _courseService.DeleteBulkUploadCourses(UKPRN);
                    deleteSuccess = deleteBulkuploadResults.IsSuccess;

                    var finishTimestamp = DateTime.UtcNow;
                    _logger.LogInformation($"{finishTimestamp.ToString("yyyyMMddHHmmss")} background worker {guid} finished successfully for {tag}");
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Error whilst deleting bulk upload file on background worker {guid} for {tag}", ex);
                }

                _logger.LogInformation($"Queued Background Task {guid} is complete.");
            });

            // COUR-1972 make sure we get a date on the Delete Confirmation page even if the physical delete above didn't find any files to delete.
            if (null != provider.BulkUploadStatus)
            {
                if (provider.BulkUploadStatus.StartedTimestamp.HasValue)
                {
                    fileUploadDate = provider.BulkUploadStatus.StartedTimestamp.Value.ToLocalTime();
                }
            }

            if (deleteSuccess)
            {
                return(RedirectToAction("DeleteFileConfirmation", "Bulkupload", new { fileUploadDate = fileUploadDate }));
            }
            else
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Delete All Bulk Uploaded Courses Error" }));
            }
        }