Exemple #1
0
        public async Task <IActionResult> ProviderApprenticeshipsSearch([FromQuery] ProviderApprenticeShipSearchRequestModel requestModel)
        {
            int?UKPRN = Session.GetInt32("UKPRN");

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

            var liveApprenticeships = await _sqlQueryDispatcher.ExecuteQuery(new GetApprenticeshipsForProvider()
            {
                ProviderId = _providerContextProvider.GetProviderId(withLegacyFallback: true)
            });

            var model = new ProviderApprenticeshipsSearchResultModel();

            if (string.IsNullOrWhiteSpace(requestModel.SearchTerm))
            {
                model.Items = liveApprenticeships.Select(Apprenticeship.FromSqlModel).ToList();
            }
            else
            {
                var searchTermWords = requestModel.SearchTerm.Split(' ', StringSplitOptions.RemoveEmptyEntries);

                model.Items = liveApprenticeships
                              .Where(r =>
                                     $"{r.Standard.StandardName} {r.MarketingInformation} {r.Standard.NotionalNVQLevelv2}"
                                     .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                     .Any(w => searchTermWords.Any(s => s.Equals(w, StringComparison.OrdinalIgnoreCase))))
                              .Select(Apprenticeship.FromSqlModel)
                              .ToList();
            }

            return(ViewComponent(nameof(ProviderApprenticeshipSearchResult), model));
        }
        public async Task <IActionResult> ProviderApprenticeshipsSearch([FromQuery] ProviderApprenticeShipSearchRequestModel requestModel)
        {
            ProviderApprenticeshipsSearchResultModel model = new ProviderApprenticeshipsSearchResultModel();

            int?UKPRN  = Session.GetInt32("UKPRN");
            var result = await _apprenticeshipService.GetApprenticeshipByUKPRN(UKPRN.ToString());


            if (result.IsSuccess)
            {
                var liveApprenticeships = result.Value.Where(a => a.RecordStatus == RecordStatus.Live);

                if (string.IsNullOrWhiteSpace(requestModel.SearchTerm))
                {
                    model.Items = liveApprenticeships.ToList();
                }
                else
                {
                    var searchTermWords = requestModel.SearchTerm.Split(' ', StringSplitOptions.RemoveEmptyEntries);

                    model.Items = liveApprenticeships
                                  .Where(r => $"{r.ApprenticeshipTitle} {r.MarketingInformation} {r.NotionalNVQLevelv2}".Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                         .Any(w => searchTermWords.Any(s => s.Equals(w, StringComparison.OrdinalIgnoreCase))) &&
                                         r.RecordStatus == RecordStatus.Live).ToList();
                }
            }

            return(ViewComponent(nameof(ViewComponents.ProviderApprenticeships.ProviderApprenticeshipSearchResult.ProviderApprenticeshipSearchResult), model));
        }
        public async Task <IActionResult> ProviderApprenticeshipsSearch([FromQuery] ProviderApprenticeShipSearchRequestModel requestModel)
        {
            int?UKPRN = Session.GetInt32("UKPRN");

            var liveApprenticeships = await _cosmosDbQueryDispatcher.ExecuteQuery(new GetApprenticeships
            {
                Predicate = a =>
                            a.ProviderUKPRN == UKPRN &&
                            a.RecordStatus == (int)ApprenticeshipStatus.Live
            });

            var model = new ProviderApprenticeshipsSearchResultModel();

            if (string.IsNullOrWhiteSpace(requestModel.SearchTerm))
            {
                model.Items = liveApprenticeships.Values.Select(Apprenticeship.FromCosmosDbModel).ToList();
            }
            else
            {
                var searchTermWords = requestModel.SearchTerm.Split(' ', StringSplitOptions.RemoveEmptyEntries);

                model.Items = liveApprenticeships.Values
                              .Where(r =>
                                     $"{r.ApprenticeshipTitle} {r.MarketingInformation} {r.NotionalNVQLevelv2}"
                                     .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                     .Any(w => searchTermWords.Any(s => s.Equals(w, StringComparison.OrdinalIgnoreCase))) &&
                                     r.RecordStatus == (int)ApprenticeshipStatus.Live)
                              .Select(Apprenticeship.FromCosmosDbModel)
                              .ToList();
            }

            return(ViewComponent(nameof(ProviderApprenticeshipSearchResult), model));
        }