public async Task <IActionResult> Search([FromQuery] SearchRequestModel requestModel)
        {
            int?UKPRN = _session.GetInt32("UKPRN");

            if (!UKPRN.HasValue)
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Please select a Provider." }));
            }

            ApprenticeshipsSearchResultModel model = new ApprenticeshipsSearchResultModel();

            if (!string.IsNullOrEmpty(requestModel.SearchTerm))
            {
                var result = await _apprenticeshipService.StandardsAndFrameworksSearch(requestModel.SearchTerm, UKPRN.Value);

                var listOfApprenticeships = new List <ApprenticeShipsSearchResultItemModel>();

                if (result.IsSuccess)
                {
                    foreach (var item in result.Value.Where(r => r.ApprenticeshipType != ApprenticeshipType.FrameworkCode))
                    {
                        listOfApprenticeships.Add(new ApprenticeShipsSearchResultItemModel()
                        {
                            ApprenticeshipTitle = item.StandardName ?? item.NasTitle,
                            id                        = item.id,
                            StandardCode              = item.StandardCode,
                            Version                   = item.Version,
                            StandardSectorCode        = item.StandardSectorCode,
                            URLLink                   = item.URLLink,
                            OtherBodyApprovalRequired = item.OtherBodyApprovalRequired,
                            ApprenticeshipType        = item.ApprenticeshipType,
                            EffectiveFrom             = item.EffectiveFrom,
                            CreatedDateTimeUtc        = item.CreatedDateTimeUtc,
                            ModifiedDateTimeUtc       = item.ModifiedDateTimeUtc,
                            RecordStatusId            = item.RecordStatusId,
                            FrameworkCode             = item.FrameworkCode,
                            ProgType                  = item.ProgType,
                            PathwayCode               = item.PathwayCode,
                            PathwayName               = item.PathwayName,
                            NasTitle                  = item.NasTitle,
                            EffectiveTo               = item.EffectiveTo,
                            SectorSubjectAreaTier1    = item.SectorSubjectAreaTier1,
                            SectorSubjectAreaTier2    = item.SectorSubjectAreaTier2,
                            NotionalNVQLevelv2        = item.NotionalEndLevel,
                            ProgTypeDesc              = item.ProgTypeDesc,
                            ProgTypeDesc2             = item.ProgTypeDesc2,
                            AlreadyCreated            = item.AlreadyCreated
                        });
                    }
                }

                model.Items      = listOfApprenticeships;
                model.SearchTerm = requestModel.SearchTerm;
            }

            return(ViewComponent(nameof(ApprenticeshipSearchResult), model));
        }
示例#2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log,
            [Inject] IApprenticeshipService apprenticeshipService)
        {
            string search    = req.Query["search"];
            string fromUKPRN = req.Query["UKPRN"];
            IEnumerable <IStandardsAndFrameworks> standardsAndFrameworks = null;

            if (string.IsNullOrWhiteSpace(fromUKPRN))
            {
                return(new BadRequestObjectResult($"Empty or missing UKPRN value."));
            }

            if (!int.TryParse(fromUKPRN, out int UKPRN))
            {
                return(new BadRequestObjectResult($"Invalid UKPRN value, expected a valid integer"));
            }

            if (string.IsNullOrWhiteSpace(search))
            {
                return(new BadRequestObjectResult($"Empty or missing search value."));
            }

            try
            {
                standardsAndFrameworks = await apprenticeshipService.StandardsAndFrameworksSearch(search);

                standardsAndFrameworks = apprenticeshipService.CheckForDuplicateApprenticeships(standardsAndFrameworks, UKPRN);
                if (standardsAndFrameworks == null)
                {
                    return(new NotFoundObjectResult(search));
                }

                return(new OkObjectResult(standardsAndFrameworks));
            }
            catch (Exception e)
            {
                return(new InternalServerErrorObjectResult(e));
            }
        }