public async Task <IViewComponentResult> InvokeAsync(TrainingProviderDetailQueryViewModel searchQueryModel, ViewType viewType = ViewType.Details)
        {
            searchQueryModel.ApprenticeshipType = _apprenticeshipOrchestrator.GetApprenticeshipType(searchQueryModel.ApprenticeshipId);
            searchQueryModel.ViewType           = viewType;


            var model = await _tpOrchestrator.GetDetails(searchQueryModel);

            model.SearchQuery = searchQueryModel;

            if (searchQueryModel.ApprenticeshipType == ApprenticeshipType.Standard)
            {
                model.Apprenticeship = await _apprenticeshipOrchestrator.GetStandard(searchQueryModel.ApprenticeshipId);
            }
            else
            {
                model.Apprenticeship = await _apprenticeshipOrchestrator.GetFramework(searchQueryModel.ApprenticeshipId);
            }

            switch (searchQueryModel.ViewType)
            {
            case ViewType.Contact:
                return(View("../TrainingProvider/Details/Contact", model));

            case ViewType.Summary:
                return(View("../TrainingProvider/Details/Summary", model));

            case ViewType.Details:
            default:
                return(View("../TrainingProvider/Details/Default", model));
            }
        }
Пример #2
0
        public async Task <TrainingProviderDetailsViewModel> GetDetails(TrainingProviderDetailQueryViewModel detailsQueryModel)
        {
            var cacheKey = $"FatComponentsCache-providerdetails-{detailsQueryModel.Ukprn}-{detailsQueryModel.LocationId}-{detailsQueryModel.ApprenticeshipId}";

            var cacheEntry = await _cacheService.RetrieveFromCache <TrainingProviderDetailsViewModel>(cacheKey);

            if (cacheEntry == null)
            {
                var response = await _mediator.Send(new ApprenticeshipProviderDetailQuery()
                {
                    UkPrn = Convert.ToInt32(detailsQueryModel.Ukprn), ApprenticeshipId = detailsQueryModel.ApprenticeshipId, ApprenticeshipType = detailsQueryModel.ApprenticeshipType, LocationId = detailsQueryModel.LocationId
                });

                if (response.StatusCode == ApprenticeshipProviderDetailResponse.ResponseCodes.ApprenticeshipProviderNotFound)
                {
                    var message = $"Cannot find provider: {detailsQueryModel.Ukprn}";
                    _logger.Warn($"404 - {message}");
                    throw new HttpRequestException(message);
                }

                if (response.StatusCode == ApprenticeshipProviderDetailResponse.ResponseCodes.InvalidInput)
                {
                    var message = $"Not able to call the apprenticeship service.";
                    _logger.Warn($"{response.StatusCode} - {message}");

                    throw new HttpRequestException(message);
                }

                cacheEntry = _trainingProviderDetailsViewModelMapper.Map(response, detailsQueryModel.ApprenticeshipId);

                await _cacheService.SaveToCache(cacheKey, cacheEntry, new TimeSpan(_cacheSettings.CacheAbsoluteExpirationDays, 0, 0, 0), new TimeSpan(_cacheSettings.CacheSlidingExpirationDays, 0, 0, 0));
            }

            return(cacheEntry);
        }
        public async Task <IViewComponentResult> InvokeAsync(TrainingProviderDetailQueryViewModel providerDetailsQueryModel, TrainingProviderSearchViewModel searchQueryModel, string title = "Training provider results")
        {
            if (providerDetailsQueryModel != null)
            {
                providerDetailsQueryModel.ApprenticeshipType = _apprenticeshipOrchestrator.GetApprenticeshipType(providerDetailsQueryModel.ApprenticeshipId);
                var model = await _tpOrchestrator.GetDetails(providerDetailsQueryModel);

                model.SearchQuery = providerDetailsQueryModel;


                return(View("../TrainingProvider/Title/Default", model.Name));
            }
            else
            {
                var result = await _tpOrchestrator.GetSearchResults(searchQueryModel);



                switch (result.Status)
                {
                case ProviderSearchResponseCodes.ScotlandPostcode:
                    return(View("../TrainingProvider/Title/Scotland"));

                case ProviderSearchResponseCodes.WalesPostcode:
                    return(View("../TrainingProvider/Title/Wales"));

                case ProviderSearchResponseCodes.NorthernIrelandPostcode:
                    return(View("../TrainingProvider/Title/NorthernIreland"));

                case ProviderSearchResponseCodes.PostCodeInvalidFormat:
                    return(View("../TrainingProvider/Title/NonUK"));

                default:
                    return(View("../TrainingProvider/Title/Default", title));
                }
            }
        }
Пример #4
0
 public IActionResult Details(TrainingProviderDetailQueryViewModel model)
 {
     return(View("TrainingProvider/Details", model));
 }