public async Task <IActionResult> Details(string courseId, string runId, string r, string currentSearchTerm, ParamValues paramValues)
        {
            logService.LogInformation($"{nameof(this.Details)} has been called");

            if (paramValues == null)
            {
                logService.LogError($"paramValues is null for method: {nameof(Details)} on controller {nameof(DetailsController)}");
                return(BadRequest());
            }

            var model = new DetailsViewModel();

            runId ??= r;

            model.SearchTerm = FormatSearchParameters(paramValues, currentSearchTerm);
            if (Request.Headers.TryGetValue(HeaderNames.Referer, out var refererValues))
            {
                model.BackLinkUrl = refererValues.FirstOrDefault(x => x.Contains("job-profiles"));
            }

            if (string.IsNullOrEmpty(courseId) || string.IsNullOrEmpty(runId))
            {
                logService.LogError($"Course Id ({courseId}) and/or runId ({runId}) does not have a value - returning NotFound");
                return(NotFound());
            }

            try
            {
                model.CourseDetails = await findACourseService.GetCourseDetails(courseId, runId).ConfigureAwait(false);

                if (model.CourseDetails == null)
                {
                    logService.LogWarning($"Get course details retrieved no data. The values passed were: course id: {courseId} and run id: {runId}");
                    return(NotFound());
                }

                model.CourseRegions = model.CourseDetails.SubRegions != null?TransformSubRegionsToRegions(model.CourseDetails.SubRegions) : null;

                model.DetailsRightBarViewModel.Provider         = mapper.Map <ProviderViewModel>(model.CourseDetails.ProviderDetails);
                model.DetailsRightBarViewModel.SpeakToAnAdviser = await staticContentDocumentService.GetByIdAsync(new Guid(cmsApiClientOptions.ContentIds)).ConfigureAwait(false);

                model.CourseDetails.CourseWebpageLink = CompareProviderLinkWithCourseLink(model?.CourseDetails?.CourseWebpageLink, model.CourseDetails?.ProviderDetails?.Website);
                model.CourseDetails.HasCampaignCode   = paramValues.CampaignCode == "LEVEL3_FREE";
            }
            catch (Exception ex)
            {
                logService.LogError($"Get course details caused an error: {ex}. The values passed were: course id: {courseId} and run id: {runId}");
                return(DetailsErrorReturnStatus(ex));
            }

            return(View(model));
        }
Exemple #2
0
        public async Task <IActionResult> Details(string courseId, string runId, string r, string currentSearchTerm, ParamValues paramValues)
        {
            logService.LogInformation($"{nameof(this.Details)} has been called");

            if (paramValues == null)
            {
                throw new ArgumentNullException(nameof(paramValues));
            }

            var model = new DetailsViewModel();

            runId ??= r;

            model.SearchTerm = FormatSearchParameters(paramValues, currentSearchTerm);

            if (string.IsNullOrEmpty(courseId) || string.IsNullOrEmpty(runId))
            {
                throw new ArgumentNullException("Course Id and/or runId does not have a value");
            }

            try
            {
                model.CourseDetails = await findACourseService.GetCourseDetails(courseId, runId).ConfigureAwait(false);

                model.CourseRegions = model.CourseDetails.SubRegions != null?TransformSubRegionsToRegions(model.CourseDetails.SubRegions) : null;

                model.DetailsRightBarViewModel.Provider         = mapper.Map <ProviderViewModel>(model.CourseDetails.ProviderDetails);
                model.DetailsRightBarViewModel.SpeakToAnAdviser = await staticContentDocumentService.GetByIdAsync(new Guid(cmsApiClientOptions.ContentIds)).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                logService.LogError($"Get course details caused an error: {ex}. The values passed were: course id: {courseId} and run id: {runId}");

                //Return an error code to cause the problem page to be displayed, previously this was returning OK with an empty model,
                //this causes errors in the view and then goes to the problem page
                return(StatusCode((int)HttpStatusCode.FailedDependency));
            }

            return(View(model));
        }