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 IActionResult AddEmployer(string employerIdentifier, string returnUrl)
        {
            //Check the parameters are populated
            if (string.IsNullOrWhiteSpace(employerIdentifier))
            {
                return(new HttpBadRequestResult($"Missing {nameof(employerIdentifier)}"));
            }

            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                return(new HttpBadRequestResult($"Missing {nameof(returnUrl)}"));
            }

            //Get the employer from the encrypted identifier
            EmployerSearchModel employer = GetEmployer(employerIdentifier);

            //Add the employer to the compare list
            CompareViewService.AddToBasket(employer.OrganisationIdEncrypted);

            //Save the compared employers to the cookie
            CompareViewService.SaveComparedEmployersToCookie(Request);

            //Redirect the user to the original page
            return(LocalRedirect(returnUrl));
        }
        public IActionResult ClearEmployers(string returnUrl)
        {
            //Check the parameters are populated
            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                return(new HttpBadRequestResult($"Missing {nameof(returnUrl)}"));
            }

            CompareViewService.ClearBasket();

            //Save the compared employers to the cookie
            CompareViewService.SaveComparedEmployersToCookie(Request);

            return(LocalRedirect(returnUrl));
        }
        public IActionResult AddEmployerJs(string employerIdentifier, string returnUrl)
        {
            //Check the parameters are populated
            if (string.IsNullOrWhiteSpace(employerIdentifier))
            {
                return(new HttpBadRequestResult($"Missing {nameof(employerIdentifier)}"));
            }

            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                return(new HttpBadRequestResult($"Missing {nameof(returnUrl)}"));
            }

            //Get the employer from the encrypted identifier
            EmployerSearchModel employer = GetEmployer(employerIdentifier);

            //Add the employer to the compare list
            CompareViewService.AddToBasket(employer.OrganisationIdEncrypted);

            //Save the compared employers to the cookie
            CompareViewService.SaveComparedEmployersToCookie(Request);

            //Setup compare basket
            bool fromSearchResults = returnUrl.Contains("/search-results");
            bool fromEmployer      = returnUrl.StartsWithI("/employer");

            ViewBag.BasketViewModel = new CompareBasketViewModel {
                CanAddEmployers = false,
                CanClearCompare = true,
                CanViewCompare  = fromSearchResults && CompareViewService.BasketItemCount > 1 ||
                                  fromEmployer && CompareViewService.BasketItemCount > 0,
                IsSearchPage   = fromSearchResults,
                IsEmployerPage = fromEmployer
            };

            ViewBag.ReturnUrl = returnUrl;

            var model = new AddRemoveButtonViewModel {
                OrganisationIdEncrypted = employer.OrganisationIdEncrypted, OrganisationName = employer.Name
            };

            return(PartialView("Basket_Button", model));
        }