public async Task <IActionResult> GetLatestJobForSpecification([FromRoute] string specificationId, [FromRoute] string jobTypes)
        {
            string[] jobTypesArray = jobTypes.Split(',', StringSplitOptions.RemoveEmptyEntries);

            ApiResponse <JobSummary> latestJobTask = await _jobsApiClient.GetLatestJobForSpecification(specificationId, jobTypesArray);

            IActionResult errorResult = latestJobTask.IsSuccessOrReturnFailureResult("JobSummary");

            if (errorResult != null)
            {
                return(errorResult);
            }

            JobSummaryViewModel jobSummaryViewModel = _mapper.Map <JobSummaryViewModel>(latestJobTask.Content);

            return(Ok(jobSummaryViewModel));
        }
        private async Task <IActionResult> Populate(string calculationId, int?pageNumber, string searchTerm)
        {
            if (string.IsNullOrWhiteSpace(calculationId))
            {
                return(new BadRequestObjectResult(ErrorMessages.CalculationIdNullOrEmpty));
            }

            await PopulateCalculation(calculationId);

            if (Calculation == null)
            {
                _logger.Error($"Failed to find calculation for id {calculationId}");

                return(new NotFoundResult());
            }

            Task <ApiResponse <SpecificationSummary> > specLookupTask = _specsClient.GetSpecificationSummary(Calculation.SpecificationId);
            Task <ApiResponse <IEnumerable <DatasetSchemasAssigned> > > datasetSchemaTask = _datasetsClient.GetAssignedDatasetSchemasForSpecification(Calculation.SpecificationId);
            Task <ApiResponse <JobSummary> > latestJobTask = _jobsClient.GetLatestJobForSpecification(Calculation.SpecificationId, new[] { JobTypes.CalculationInstruct, JobTypes.CalculationAggregration });

            await TaskHelper.WhenAllAndThrow(specLookupTask, datasetSchemaTask, latestJobTask);

            ApiResponse <JobSummary> latestJobResponse = latestJobTask.Result;

            // There may not be a latest job for the current spec so don't fail if there isn't one
            if (latestJobResponse != null)
            {
                if (latestJobResponse.Content == null)
                {
                    LatestJobJson = "null";
                }
                else
                {
                    LatestJobJson = JsonConvert.SerializeObject(latestJobResponse.Content);
                }
            }

            ApiResponse <IEnumerable <DatasetSchemasAssigned> > datasetSchemaResponse = datasetSchemaTask.Result;

            if (datasetSchemaResponse == null || (!datasetSchemaResponse.StatusCode.IsSuccess() || datasetSchemaResponse.Content == null))
            {
                _logger.Error("A Problem occcured getting assigned dataset schemas");

                return(new StatusCodeResult(500));
            }

            ApiResponse <SpecificationSummary> specResponse = specLookupTask.Result;

            if (specResponse == null || (!specResponse.StatusCode.IsSuccess() || specResponse.Content == null))
            {
                _logger.Warning("Unable to retrieve Specification Summary with Spec ID '{SpecificationId}' for Calculation ID '{Id}", Calculation.SpecificationId, Calculation.Id);

                return(new InternalServerErrorResult($"Unable to retrieve Specification Summary with Spec ID '{Calculation.SpecificationId}' for Calculation ID '{Calculation.Id}"));
            }

            Specification = _mapper.Map <SpecificationSummaryViewModel>(specResponse.Content);

            HasProviderDatasetsAssigned = datasetSchemaResponse.Content.Any(d => d.IsSetAsProviderData);

            if (HasProviderDatasetsAssigned)
            {
                await PerformSearch(calculationId, pageNumber, searchTerm);

                if (CalculationProviderResults == null)
                {
                    _logger.Error("Null calculation provider results were returned from the search api");

                    return(new StatusCodeResult(500));
                }

                SearchTerm = searchTerm;
            }

            return(Page());
        }