public async Task <ActionResult> Download(Guid id, eFileFormat fileFormat, int step, int totalSteps, string searchQueryString = null, eLookupSearchSource?searchSource = null) { var model = new ProgressDto(); try { model = await _governorDownloadService.GetDownloadGenerationProgressAsync(id, User); } catch (Exception ex) { if (ex.Message.StartsWith("The API returned 404 Not Found")) { // if the file no longer exists (user refreshes the page post download etc) then the api returns a 404 and throws an error. This allows for a more graceful response model.Error = "Download process not found for associated id"; } else { throw; } } var viewModel = new GovernorSearchDownloadGenerationProgressViewModel(model) { FileFormat = fileFormat, SearchSource = searchSource, SearchQueryString = searchQueryString, Step = step, TotalSteps = totalSteps }; if (model.HasErrored) { return(View("Downloads/DownloadError", new DownloadErrorViewModel { SearchQueryString = searchQueryString, SearchSource = searchSource, NeedsRegenerating = true })); } viewModel.Step++; if (!model.IsComplete) { return(View("Downloads/PreparingFilePleaseWait", viewModel)); } viewModel.Step++; return(View("Downloads/ReadyToDownload", viewModel)); }
public async Task <ActionResult> Download(Guid id, eFileFormat fileFormat, int step, int totalSteps, string searchQueryString = null, eLookupSearchSource?searchSource = null) { var model = await _governorDownloadService.GetDownloadGenerationProgressAsync(id, User); var viewModel = new GovernorSearchDownloadGenerationProgressViewModel(model) { FileFormat = fileFormat, SearchSource = searchSource, SearchQueryString = searchQueryString, Step = step, TotalSteps = totalSteps }; if (model.HasErrored) { throw new Exception($"Download generation failed; Underlying error: '{model.Error}'"); } if (!model.IsComplete) { return(View("Downloads/PreparingFilePleaseWait", viewModel)); } viewModel.Step++; return(View("Downloads/ReadyToDownload", viewModel)); }