public ActionResult Index(PsfModel model, PsfSearchResultsViewModel resultsViewModel)
        {
            CheckForBackState(model);

            // If the previous page is search page then, there will not be any sections in the passed PSFModel
            var previousPsfPage = model?.Section == null ? resultsViewModel?.PreSearchFiltersModel : model;

            if (previousPsfPage != null)
            {
                preSearchFilterStateManager.RestoreState(previousPsfPage.OptionsSelected);
                if (preSearchFilterStateManager.ShouldSaveState(ThisPageNumber, previousPsfPage.Section.PageNumber))
                {
                    var previousFilterSection = autoMapper.Map <PreSearchFilterSection>(previousPsfPage.Section);
                    preSearchFilterStateManager.SaveState(previousFilterSection);
                }
            }

            var currentPageFilter = GetCurrentPageFilter();

            if (ThisPageNumber > 1 && UsePageProfileCount)
            {
                var numberOfMatches = asyncHelper.Synchronise(() => GetNumberOfMatches(currentPageFilter));
                currentPageFilter.NumberOfMatchesMessage = string.Format(NumberOfMatchesMessage, numberOfMatches);
                currentPageFilter.UsePageProfileCount    = UsePageProfileCount;
            }

            return(View(currentPageFilter));
        }
Beispiel #2
0
        private PsfSearchResultsViewModel GetPsfSearchResultsViewModel(PsfModel model, bool notPaging)
        {
            preSearchFilterStateManager.RestoreState(model.OptionsSelected);
            if (notPaging)
            {
                if (model.Section.SingleSelectedValue != null)
                {
                    model.Section.SingleSelectOnly = true;
                    var optionSelec =
                        model.Section.Options.FirstOrDefault(o => o.OptionKey == model.Section.SingleSelectedValue);
                    if (optionSelec != null)
                    {
                        optionSelec.IsSelected = true;
                    }
                }
                else
                {
                    model.Section.SingleSelectOnly = false;
                }

                var psfilterSection = mapper.Map <PreSearchFilterSection>(model.Section);

                preSearchFilterStateManager.UpdateSectionState(psfilterSection);
            }

            var filterState = preSearchFilterStateManager.GetPreSearchFilterState();

            model.Sections = mapper.Map <List <PsfSection> >(filterState.Sections);

            var resultModel = new PsfSearchResultsViewModel
            {
                MainPageTitle         = MainPageTitle,
                SecondaryText         = SecondaryText,
                OverviewMessage       = OverviewMessage,
                PreSearchFiltersModel = new PsfModel
                {
                    OptionsSelected = preSearchFilterStateManager.GetStateJson(),
                    Section         = new PsfSection
                    {
                        PageNumber = notPaging ? model.Section.PageNumber++ : model.Section.PageNumber
                    }
                },
                BackPageUrl            = new Uri(BackPageUrl, UriKind.RelativeOrAbsolute),
                BackPageUrlText        = BackPageUrlText,
                JobProfileCategoryPage = JobProfileCategoryPage,
                SalaryBlankText        = SalaryBlankText,
                CaveatTagMarkup        = CaveatTagMarkup,
                CaveatMarkup           = CaveatMarkup
            };

            //Need to do this to force the model we have changed to refresh
            ModelState.Clear();

            return(resultModel);
        }
        public void IndexNoModelTest()
        {
            //Setup the fakes and dummies for test
            SetUpFakesAndCalls();
            SetUpStateMangerFakesAndCalls(PreSearchFilterType.Interest, false);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <JobProfilesAutoMapperProfile>();
            });
            var mapper = config.CreateMapper();

            //Instantiate & Act
            var preSearchFiltersController =
                new PreSearchFiltersController(loggerFake, mapper, psfRepositoryFactoryFake, fakePsfStateManager)
            {
                FilterType = PreSearchFilterType.Interest
            };

            //Act on the index
            var indexResult = preSearchFiltersController.WithCallTo(c => c.Index());

            PsfModel firstVm = null;

            //Assert
            indexResult.ShouldRenderDefaultView().WithModel <PsfModel>(vm =>
            {
                CheckFilterSecton(preSearchFiltersController, vm.Section, PreSearchFilterType.Interest);
                firstVm = vm;
            }).AndNoModelErrors();

            A.CallTo(() => psfFakeIntrestRepository.GetAllFilters()).MustHaveHappened();

            A.CallTo(() => fakePsfStateManager.RestoreState(A <string> ._)).MustNotHaveHappened();
            A.CallTo(() => fakePsfStateManager.ShouldSaveState(A <int> ._, A <int> ._)).MustNotHaveHappened();
            A.CallTo(() => fakePsfStateManager.SaveState(A <PreSearchFilterSection> ._)).MustNotHaveHappened();

            A.CallTo(() => fakePsfStateManager.GetSavedSection(A <string> ._, A <PreSearchFilterType> ._)).MustHaveHappened();
            A.CallTo(() => fakePsfStateManager.RestoreOptions(A <PreSearchFilterSection> ._, A <IEnumerable <PreSearchFilter> > ._)).MustHaveHappened();
            A.CallTo(() => fakePsfStateManager.GetStateJson()).MustHaveHappened();
        }
        private void SetUpStateMangerFakesAndCalls(PreSearchFilterType filterType, bool shouldSaveState, bool addNotApplicable = true)
        {
            var dummyStateSection = new PreSearchFilterSection
            {
                SectionDataType = filterType,
                Options         = GetDummyPreSearchFilterOption(addNotApplicable)
            };

            fakePsfStateManager = A.Fake <IPreSearchFilterStateManager>(ops => ops.Strict());
            A.CallTo(() => fakePsfStateManager.GetSavedSection(A <string> ._, A <PreSearchFilterType> ._)).Returns(dummyStateSection);
            A.CallTo(() => fakePsfStateManager.RestoreOptions(A <PreSearchFilterSection> ._, A <IEnumerable <PreSearchFilter> > ._)).Returns(dummyStateSection);
            A.CallTo(() => fakePsfStateManager.GetStateJson()).Returns("DummyStateJson");
            A.CallTo(() => fakePsfStateManager.ShouldSaveState(A <int> ._, A <int> ._)).Returns(shouldSaveState);
            A.CallTo(() => fakePsfStateManager.RestoreState(A <string> ._)).DoesNothing();
            A.CallTo(() => fakePsfStateManager.SaveState(A <PreSearchFilterSection> ._)).DoesNothing();
        }
        public ActionResult Index(PsfModel model, PsfSearchResultsViewModel resultsViewModel)
        {
            // If the previous page is search page then, there will not be any sections in the passed PSFModel
            var previousPsfPage = model?.Section == null ? resultsViewModel?.PreSearchFiltersModel : model;

            if (previousPsfPage != null)
            {
                preSearchFilterStateManager.RestoreState(previousPsfPage.OptionsSelected);
                if (preSearchFilterStateManager.ShouldSaveState(ThisPageNumber, previousPsfPage.Section.PageNumber))
                {
                    var previousFilterSection = autoMapper.Map <PreSearchFilterSection>(previousPsfPage.Section);
                    preSearchFilterStateManager.SaveState(previousFilterSection);
                }
            }

            var currentPageFilter = GetCurrentPageFilter();

            return(View(currentPageFilter));
        }