예제 #1
0
        //public IDictionary<Guid, Recruiter> GetRecruiters(IEnumerable<Guid> recruiterIds)
        //{
        //    if(recruiterIds == null)
        //    {
        //        throw new ArgumentNullException(nameof(recruiterIds));
        //    }

        //    return _context.Recruiters.Where(a => recruiterIds.Contains(a.Id)).ToDictionary(x=>x.Id, y=>y);
        //}

        public async Task <IPagedList <ExtendedUser> > GetExtendedUsersAsync(ExtendedUsersResourceParameters recruitersResourceParameters)
        {
            if (recruitersResourceParameters == null)
            {
                throw new ArgumentNullException(nameof(recruitersResourceParameters));
            }

            var collection = _context.Recruiters as IQueryable <ExtendedUser>;

            var recruiterPosition = recruitersResourceParameters.RecruiterPosition.ToRecruiterPosition();

            if (recruiterPosition != RecruiterPosition.Undefined)
            {
                collection = collection.Where(a => a.Position == recruiterPosition);
            }

            var companyId = recruitersResourceParameters.CompanyId;

            if (companyId != null)
            {
                collection = collection.Where(a => a.CompanyId.ToString() == companyId);
            }

            if (!string.IsNullOrWhiteSpace(recruitersResourceParameters.SearchQuery))
            {
                var searchQuery = recruitersResourceParameters.SearchQuery.Trim();
                collection = collection.Where(a => a.Company.Name.ToLower().Contains(searchQuery.ToLower()));
            }

            if (!string.IsNullOrWhiteSpace(recruitersResourceParameters.OrderBy))
            {
                // get property mapping dictionary
                var recruiterMappingDictionary = _propertyMappingService.GetPropertyMapping <ExtendedUserDto, ExtendedUser>();

                collection = collection.ApplySort(recruitersResourceParameters.OrderBy, recruiterMappingDictionary);
            }

            return(await Utils.PagedList <ExtendedUser> .Create(collection, recruitersResourceParameters.PageNumber, recruitersResourceParameters.PageSize));
        }
예제 #2
0
        public async Task <IActionResult> GetRecruiters([FromQuery] ExtendedUsersResourceParameters recruitersResourceParameters, [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!MediaTypeHeaderValue.TryParse(mediaType, out MediaTypeHeaderValue parsedMediaType))
            {
                _logger.LogInformation($"Media type header value [{mediaType}] not parsable");
                return(BadRequest());
            }

            if (!_propertyCheckerService.TypeHasProperties <ExtendedUserDto>(recruitersResourceParameters.Fields))
            {
                _logger.LogInformation($"Property checker did not find on of the Recruiter resource parameters fields");
                return(BadRequest());
            }

            if (!_propertyMappingService.ValidMappingExistsFor <ExtendedUserDto, ExtendedUser>
                    (recruitersResourceParameters.OrderBy))
            {
                return(BadRequest());
            }

            var recruitersFromRepo = await _repository.GetExtendedUsersAsync(recruitersResourceParameters);

            return(Ok(recruitersFromRepo));
        }