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));
        }
        // 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));
        }
        public IActionResult Employer(string employerIdentifier)
        {
            if (string.IsNullOrWhiteSpace(employerIdentifier))
            {
                return(new HttpBadRequestResult("Missing employer identifier"));
            }

            CustomResult <Organisation> organisationLoadingOutcome;

            try
            {
                organisationLoadingOutcome = OrganisationBusinessLogic.LoadInfoFromActiveEmployerIdentifier(employerIdentifier);

                if (organisationLoadingOutcome.Failed)
                {
                    return(organisationLoadingOutcome.ErrorMessage.ToHttpStatusViewResult());
                }
            }
            catch (Exception ex)
            {
                CustomLogger.Error($"Cannot decrypt return employerIdentifier from '{employerIdentifier}'", ex);
                return(View("CustomError", new ErrorViewModel(400)));
            }

            //Clear the default back url of the report page
            ReportBackUrl = null;

            ViewBag.BasketViewModel = new CompareBasketViewModel {
                CanAddEmployers = true, CanViewCompare = true
            };

            return(View(
                       "EmployerDetails/Employer",
                       new EmployerDetailsViewModel {
                Organisation = organisationLoadingOutcome.Result,
                LastSearchUrl = SearchViewService.GetLastSearchUrl(),
                EmployerBackUrl = EmployerBackUrl,
                ComparedEmployers = CompareViewService.ComparedEmployers.Value
            }));
        }
Exemple #4
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());
            }
        }
        public IActionResult CompareEmployers(int year, string employers = null)
        {
            if (year == 0)
            {
                CompareViewService.SortColumn    = null;
                CompareViewService.SortAscending = true;
                year = ReportingYearsHelper.GetTheMostRecentCompletedReportingYear();
            }

            //Load employers from querystring (via shared email)
            if (!string.IsNullOrWhiteSpace(employers))
            {
                string[] comparedEmployers = employers.SplitI("-");
                if (comparedEmployers.Any())
                {
                    CompareViewService.ClearBasket();
                    CompareViewService.AddRangeToBasket(comparedEmployers);
                    CompareViewService.SortAscending = true;
                    CompareViewService.SortColumn    = null;
                    return(RedirectToAction("CompareEmployers", new { year }));
                }
            }

            //If the session is lost then load employers from the cookie
            else if (CompareViewService.BasketItemCount == 0)
            {
                CompareViewService.LoadComparedEmployersFromCookie();
            }

            ViewBag.ReturnUrl = Url.Action("CompareEmployers", new { year });

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

            //Get the compare basket organisations
            IEnumerable <CompareReportModel> compareReports = OrganisationBusinessLogic.GetCompareData(
                CompareViewService.ComparedEmployers.Value.AsEnumerable(),
                year,
                CompareViewService.SortColumn,
                CompareViewService.SortAscending);

            //Track the compared employers
            string lastComparedEmployerList = CompareViewService.ComparedEmployers.Value.ToList().ToSortedSet().ToDelimitedString();

            if (CompareViewService.LastComparedEmployerList != lastComparedEmployerList && IsAction("CompareEmployers"))
            {
                SortedSet <string> employerIds = compareReports.Select(r => r.EncOrganisationId).ToSortedSet();
                WebTracker.TrackPageView(
                    this,
                    $"compare-employers: {employerIds.ToDelimitedString()}",
                    $"{ViewBag.ReturnUrl}?{employerIds.ToEncapsulatedString("e=", null, "&", "&", false)}");
                foreach (CompareReportModel employer in compareReports)
                {
                    WebTracker.TrackPageView(
                        this,
                        $"{employer.EncOrganisationId}: {employer.OrganisationName}",
                        $"{ViewBag.ReturnUrl}?{employer.EncOrganisationId}={employer.OrganisationName}");
                }

                CompareViewService.LastComparedEmployerList = lastComparedEmployerList;
            }

            //Generate the shared links
            string shareEmailUrl = Url.Action(
                nameof(CompareEmployers),
                "Compare",
                new { year, employers = CompareViewService.ComparedEmployers.Value.ToList().ToDelimitedString("-") },
                Request.Scheme);

            ViewBag.BasketViewModel = new CompareBasketViewModel {
                CanAddEmployers = true, CanViewCompare = false, CanClearCompare = true
            };

            return(View(
                       "CompareEmployers",
                       new CompareViewModel {
                LastSearchUrl = SearchViewService.GetLastSearchUrl(),
                CompareReports = compareReports,
                CompareBasketCount = CompareViewService.BasketItemCount,
                ShareEmailUrl =
                    CompareViewService.BasketItemCount <= CompareViewService.MaxCompareBasketShareCount ? shareEmailUrl : null,
                Year = year,
                SortAscending = CompareViewService.SortAscending,
                SortColumn = CompareViewService.SortColumn
            }));
        }