Esempio n. 1
0
        public async Task <IActionResult> Get(int ukprn)
        {
            _log.LogDebug($"Fetching GET for ukprn: [{ukprn}]");

            if (ukprn.ToString().Length != 8)
            {
                _log.LogDebug($"Invalid UKPRN (must be 8 numbers): [{ukprn}]");
                return(BadRequest("Invalid UKPRN (should be 8 numbers long)"));
            }

            IEnumerable <RoatpResult> roatpResults;

            try
            {
                var result = _retryService.RetryPolicy($"<roatpService>//api/v1/download/roatp-summary/{ukprn}").ExecuteAsync(context => _apiClient.GetRoatpSummaryByUkprn(ukprn), new Context());
                roatpResults = result.Result;
            }
            catch (Exception ex)
            {
                _log.LogError($"Unable to retrieve results for roatp with ukprn [{ukprn}]", ex);
                roatpResults = new List <RoatpResult>();
            }

            var provider = _mapper.Map(roatpResults?.FirstOrDefault());

            if (provider == null || !provider.IsDateValid(DateTime.UtcNow))
            {
                _log.LogDebug($"Invalid UKPRN result for ukprn [{ukprn}]: not found or start date in future");
                return(NotFound("Provider not found or start date in future"));
            }
            provider.Uri = Resolve(provider.Ukprn);
            return(Ok(provider));
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            DateTime?date = DateTime.Now;

            try
            {
                var result = _retryService.RetryPolicy("<roatpService>/api/v1/download/roatp-summary/most-recent").ExecuteAsync(context => _apiClient.GetLatestNonOnboardingOrganisationChangeDate(), new Context());
                date = result.Result;
            }
            catch (Exception ex)
            {
                _logger.LogError("Unable to retrieve results for latest non-onboarding organisation change", ex);
                date = DateTime.Now;
            }

            var viewModel = new RoatpDownloadViewModel {
                Filename = GenerateFilename(date.Value), LastUpdated = date.Value
            };

            return(View(viewModel));
        }