Exemple #1
0
        public async Task <ActionResult> Download(Guid id, eFileFormat fileFormat, string searchQueryString = null,
                                                  eLookupSearchSource?searchSource = null)
        {
            var model = new ProgressDto();

            try
            {
                model = await _establishmentDownloadService.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 EstablishmentSearchDownloadGenerationProgressViewModel(model)
            {
                FileFormat        = fileFormat,
                SearchSource      = searchSource,
                SearchQueryString = searchQueryString
            };

            if (model.HasErrored)
            {
                return(View("Downloads/DownloadError", new DownloadErrorViewModel {
                    SearchQueryString = searchQueryString, SearchSource = searchSource, NeedsRegenerating = true
                }));
            }

            if (!model.IsComplete)
            {
                return(View("Downloads/PreparingFilePleaseWait", viewModel));
            }

            return(View("Downloads/ReadyToDownload", viewModel));
        }
Exemple #2
0
        public async Task <ActionResult> Download(Guid id, eFileFormat fileFormat, string searchQueryString = null, eLookupSearchSource?searchSource = null)
        {
            var model = await _establishmentDownloadService.GetDownloadGenerationProgressAsync(id, User);

            var viewModel = new EstablishmentSearchDownloadGenerationProgressViewModel(model, model.IsComplete ? 4 : 3)
            {
                FileFormat        = fileFormat,
                SearchSource      = searchSource,
                SearchQueryString = searchQueryString
            };

            if (model.HasErrored)
            {
                throw new Exception($"Download generation failed; Underlying error: '{model.Error}'");
            }

            if (!model.IsComplete)
            {
                return(View("Downloads/PreparingFilePleaseWait", viewModel));
            }

            return(View("Downloads/ReadyToDownload", viewModel));
        }