public IActionResult Search(string country, string what, string where, int page = 1) { //Encodes any special characters in the search string, then gets data from the API and puts it in a results list string encodedWhat; if (what.Contains('%')) { encodedWhat = what; } else { encodedWhat = WebUtility.UrlEncode(what); } string encodedWhere; if (where.Contains('%')) { encodedWhere = where; } else { encodedWhere = WebUtility.UrlEncode(where); } Rootobject r = jd.SearchJobs(country.ToLower(), page, encodedWhat, encodedWhere); List <Result> jobResults = r.results.ToList(); //If user is logged in, hide results the user already has saved in their tracker if (User.Identity.IsAuthenticated) { //Gets the Link property of all jobs the user has saved, remove any null values List <string> dbJobLinks = _context.Jobs.Where(x => x.UserId == User.FindFirst(ClaimTypes.NameIdentifier).Value).Select(x => x.Link).ToList(); dbJobLinks = dbJobLinks.Where(x => x != null).ToList(); List <Result> duplicates = new List <Result>(); //Adds job results from API to a duplicates list if their link matches one in the DB foreach (Result result in jobResults) { if (dbJobLinks.Any(x => TextHelper.CompareJobUrl(x, result.redirect_url))) { duplicates.Add(result); } } //Removes duplicates from results to display foreach (Result rd in duplicates) { jobResults.Remove(rd); } } //Stores query parameters in TempData so user can page through results without having to search again TempData["country"] = country; TempData["page"] = page; TempData["what"] = what; TempData["where"] = where; return(View(jobResults)); }
public DataTable SearchJobs(int cityId, int jobCategoryId) => _jobDal.SearchJobs(cityId, jobCategoryId);