public async Task <IActionResult> SearchResults([FromQuery] SearchResultsQuery searchQuery, string orderBy = "relevance")
        {
            //When never searched in this session
            if (string.IsNullOrWhiteSpace(SearchViewService.LastSearchParameters))
            {
                //If no compare employers in session then load employers from the cookie
                if (CompareViewService.BasketItemCount == 0)
                {
                    CompareViewService.LoadComparedEmployersFromCookie();
                }
            }

            //Clear the default back url of the employer hub pages
            EmployerBackUrl = null;
            ReportBackUrl   = null;

            // ensure parameters are valid
            if (!searchQuery.TryValidateSearchParams(out HttpStatusViewResult result))
            {
                return(result);
            }

            // generate result view model
            var             searchParams = SearchResultsQueryToEmployerSearchParameters(searchQuery);
            SearchViewModel model        = await ViewingService.SearchAsync(searchParams, orderBy);

            ViewBag.ReturnUrl = SearchViewService.GetLastSearchUrl();

            ViewBag.BasketViewModel = new CompareBasketViewModel {
                CanAddEmployers = false, CanViewCompare = CompareViewService.BasketItemCount > 1, CanClearCompare = true
            };

            return(View("Finder/SearchResults", model));
        }
        public async Task <IActionResult> AddSearchResultsToCompare([FromQuery] SearchResultsQuery searchQuery, string orderBy = "relevance")
        {
            if (!searchQuery.TryValidateSearchParams(out HttpStatusViewResult result))
            {
                return(result);
            }

            // generate compare list
            var searchParams = SearchResultsQueryToEmployerSearchParameters(searchQuery);

            // set maximum search size
            searchParams.Page     = 1;
            searchParams.PageSize = CompareViewService.MaxCompareBasketCount;
            SearchViewModel searchResultsModel = await ViewingService.SearchAsync(searchParams, orderBy);

            // add any new items to the compare list
            string[] resultIds = searchResultsModel.Employers.Results
                                 .Where(employer => CompareViewService.BasketContains(employer.OrganisationIdEncrypted) == false)
                                 .Take(CompareViewService.MaxCompareBasketCount - CompareViewService.BasketItemCount)
                                 .Select(employer => employer.OrganisationIdEncrypted)
                                 .ToArray();

            CompareViewService.AddRangeToBasket(resultIds);

            // save the results to the cookie
            CompareViewService.SaveComparedEmployersToCookie(Request);

            return(RedirectToAction(nameof(SearchResults), "Viewing", searchQuery));
        }
        public void GetOrgSizeOptions_Marks_given_org_size_indexes_as_checked_or_not_checked()
        {
            var testOptions = new[] {
                OrganisationSizes.Employees0To249, OrganisationSizes.Employees1000To4999, OrganisationSizes.Employees5000To19999
            };

            // Mocks
            var testService = new ViewingService(
                _mockDataRepo.Object,
                viewingSearchService);
            List <OptionSelect> options = testService.GetOrgSizeOptions(testOptions.Select(x => (int)x), null);

            // Assert
            for (var i = 0; i < options.Count; i++)
            {
                OptionSelect opt = options[i];

                // assert checked
                if (testOptions.Any(x => (int)x == i))
                {
                    Assert.That(opt.Checked);
                }
                else
                {
                    Assert.That(opt.Checked == false);
                }

                var size = (OrganisationSizes)Enum.Parse(typeof(OrganisationSizes), opt.Value);
                Assert.That(opt.Disabled == false);
                Assert.That(opt.Id == $"Size{i}");
                Assert.That(opt.Label == size.GetAttribute <DisplayAttribute>().Name);
                Assert.That(opt.Value == i.ToString());
            }
        }
        public async Task GetSectorOptions_Marks_given_sector_chars_as_checked_or_not_checked()
        {
            // Setup
            var testSicSections = new[] {
                new SicSection {
                    SicSectionId = "C", Description = "C Sector"
                },
                new SicSection {
                    SicSectionId = "D", Description = "D Sector"
                },
                new SicSection {
                    SicSectionId = "L", Description = "L Sector"
                },
                new SicSection {
                    SicSectionId = "O", Description = "O Sector"
                },
                new SicSection {
                    SicSectionId = "R", Description = "R Sector"
                },
                new SicSection {
                    SicSectionId = "Y", Description = "Y Sector"
                }
            };

            var testOptions = new[] { 'D', 'L', 'O' };

            // Mocks
            _mockDataRepo.Setup(x => x.GetAll <SicSection>())
            .Returns(new List <SicSection>(testSicSections).AsQueryable().BuildMock().Object);

            var testService = new ViewingService(
                _mockDataRepo.Object,
                viewingSearchService);
            List <OptionSelect> options = await testService.GetSectorOptionsAsync(testOptions, null);

            // Assert
            for (var i = 0; i < options.Count; i++)
            {
                OptionSelect opt = options[i];

                // assert checked
                if (testOptions.Any(x => x == opt.Value[0]))
                {
                    Assert.That(opt.Checked);
                }
                else
                {
                    Assert.That(opt.Checked == false);
                }

                Assert.That(opt.Disabled == false);
                Assert.That(opt.Id == testSicSections[i].SicSectionId);
                Assert.That(opt.Label == $"{testSicSections[i].SicSectionId} Sector");
                Assert.That(opt.Value == testSicSections[i].SicSectionId);
            }
        }
        public void GetReportingStatusOptions_Marks_given_status_as_checked_or_not_checked()
        {
            // Setup
            var testAllOptions = new[] {
                (int)SearchReportingStatusFilter.ReportedInTheLast7Days,
                (int)SearchReportingStatusFilter.ReportedInTheLast30Days,
                (int)SearchReportingStatusFilter.ReportedLate,
                (int)SearchReportingStatusFilter.ReportedWithCompanyLinkToGpgInfo
            };

            var testCheckedOptions = new[] {
                (int)SearchReportingStatusFilter.ReportedInTheLast7Days, (int)SearchReportingStatusFilter.ReportedLate
            };

            var testService = new ViewingService(
                _mockDataRepo.Object,
                viewingSearchService);
            List <OptionSelect> options = testService.GetReportingStatusOptions(testCheckedOptions);

            // Assert
            for (var i = 0; i < options.Count; i++)
            {
                OptionSelect opt = options[i];

                // assert checked status
                if (testCheckedOptions.Any(x => x.ToString() == opt.Value))
                {
                    Assert.That(opt.Checked);
                }
                else
                {
                    Assert.That(opt.Checked == false);
                }

                // assert all other meta
                Assert.That(opt.Disabled == false);
                Assert.That(opt.Id == $"ReportingStatus{testAllOptions[i]}");
                Assert.That(opt.Label == ((SearchReportingStatusFilter)testAllOptions[i]).GetAttribute <DisplayAttribute>().Name);
                Assert.That(opt.Value == testAllOptions[i].ToString());
            }
        }
        // used to generate suggestions for the search on the landing page
        public async Task <IActionResult> SearchResultsJs([FromQuery] SearchResultsQuery searchQuery)
        {
            //Clear the default back url of the employer hub pages
            EmployerBackUrl = null;
            ReportBackUrl   = null;


            // ensure parameters are valid
            if (!searchQuery.TryValidateSearchParams(out HttpStatusViewResult result))
            {
                return(result);
            }

            // generate result view model
            var             searchParams = SearchResultsQueryToEmployerSearchParameters(searchQuery);
            SearchViewModel model        = await ViewingService.SearchAsync(searchParams, "relevance");

            ViewBag.ReturnUrl = SearchViewService.GetLastSearchUrl();

            return(PartialView("Finder/Parts/MainContent", model));
        }
Exemple #7
0
        public async Task <IActionResult> Step1Task2([FromQuery] SearchResultsQuery searchQuery, string orderBy = "relevance")
        {
            if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.ReportingStepByStep))
            {
                //When never searched in this session
                if (string.IsNullOrWhiteSpace(SearchViewService.LastSearchParameters))
                {
                    //If no compare employers in session then load employers from the cookie
                    if (CompareViewService.BasketItemCount == 0)
                    {
                        CompareViewService.LoadComparedEmployersFromCookie();
                    }
                }

                // ensure parameters are valid
                if (!searchQuery.TryValidateSearchParams(out HttpStatusViewResult result))
                {
                    return(result);
                }

                // generate result view model
                var             searchParams = SearchResultsQueryToEmployerSearchParameters(searchQuery);
                SearchViewModel model        = await ViewingService.SearchAsync(searchParams, orderBy);

                ViewBag.ReturnUrl = SearchViewService.GetLastSearchUrl();

                ViewBag.BasketViewModel = new CompareBasketViewModel {
                    CanAddEmployers = false, CanViewCompare = CompareViewService.BasketItemCount > 1, CanClearCompare = true
                };
                return(View("../ReportingStepByStep/Step1Task2", model));
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }