public List <JobGetDto> GetDevJobs(JobPostDto search, string userId)
        {
            //Set the query of all the jobs that the developer has not applied to
            var jobsDb = db.Jobs.Include(j => j.JobsApplied).Where(j => !j.JobsApplied.Any(ja => ja.JobID == j.JobID && ja.DeveloperID == userId)).Include(j => j.Company);

            //Get a list of jobs filtered by title and location
            if (!String.IsNullOrEmpty(search.JobTitle) && !String.IsNullOrEmpty(search.CityName))
            {
                return(jobsDb.Where(j => j.JobTitle.ToLower().Contains(search.JobTitle.ToLower()) && j.Company.User.Address.City.CityName == search.CityName)
                       .Select(Mapper.Map <Job, JobGetDto>)
                       .ToList());
            }

            //Get a list of jobs filtered by title
            if (!String.IsNullOrEmpty(search.JobTitle))
            {
                return(jobsDb.Where(j => j.JobTitle.ToLower().Contains(search.JobTitle.ToLower())).Select(Mapper.Map <Job, JobGetDto>).ToList());
            }

            //Get a list of jobs filtered by location
            if (!String.IsNullOrEmpty(search.CityName))
            {
                return(jobsDb.Where(j => j.Company.User.Address.City.CityName == search.CityName).Select(Mapper.Map <Job, JobGetDto>).ToList());
            }

            return(new List <JobGetDto>());
        }
Exemple #2
0
        public IHttpActionResult JobsPage(JobPostDto search)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Something went wrong!"));
            }

            var jobs = jobRepository.GetDevJobs(search, userId);

            return(Ok(jobs));
        }