예제 #1
0
 public ActionResult ListSortedUsers(PeopleFilterViewModel filter)
 {
     if (ModelState.IsValid)
     {
         var users = _appUserService.APIFilter(filter);
         return(Ok(Mapping.Map <IEnumerable <AppUser>, IEnumerable <PersonProfileViewModel> >(users)));
     }
     return(null);
 }
예제 #2
0
        public IEnumerable <AppUser> APIFilter(PeopleFilterViewModel filter)
        {
            IEnumerable <AppUser> result = _userManager.Users.Include(user => user.CompanyAppUsers).ThenInclude(companyAppUser => companyAppUser.Company).Include(user => user.AppUserSkills).ThenInclude(appUserSkill => appUserSkill.Skill).Include(user => user.AppUserCertificates).ThenInclude(appUserCertificate => appUserCertificate.Certificate);

            // sort by location
            if (!string.IsNullOrEmpty(filter.Location))
            {
                result = result.Where(user => user.Location != null && user.Location.Trim().Contains(filter.Location.Trim(), StringComparison.InvariantCultureIgnoreCase));
            }

            // sort by industry
            if (!string.IsNullOrEmpty(filter.Industry))
            {
                result = result.Where(user => user.Industry.GetDescription() == filter.Industry);
            }

            // sort by jobTypes
            if (filter.JobTypes != null && filter.JobTypes.Count() != 0)
            {
                result = result.Where(user => filter.JobTypes.Contains(user.JobType.GetDescription(), StringComparer.InvariantCultureIgnoreCase));
            }

            // sort by skills
            if (filter.Skills != null && filter.Skills.Count() != 0)
            {
                result = result.Where(user => user.AppUserSkills.Any(appUserSkill => filter.Skills.Any(skill => skill.Equals(appUserSkill.Skill.Name, StringComparison.InvariantCultureIgnoreCase))));
            }

            // sort by experience
            if (filter.Experience != null && filter.Experience.Count() != 0)
            {
                result = result.Where(user => filter.Experience.Contains(user.Experience.GetDescription(), StringComparer.InvariantCultureIgnoreCase));
            }

            // sort by certificates
            if (filter.Certificates != null && filter.Certificates.Count() != 0)
            {
                result = result.Where(user => user.AppUserCertificates.Any(appUserCertificates => filter.Certificates.Any(certificate => certificate.Equals(appUserCertificates.Certificate.Name, StringComparison.InvariantCultureIgnoreCase))));
            }

            // sort by company name
            if (!string.IsNullOrEmpty(filter.CompanyName))
            {
                result = result.Where(user => user.CompanyAppUsers.Any(companyAppUser => companyAppUser.Company != null && companyAppUser.Company.Name.Contains(filter.CompanyName.Trim(), StringComparison.InvariantCultureIgnoreCase)));
            }

            return(result);
        }