public async Task <IPagedList <Rekommendation> > GetRekommendationsAsync(RekommendationsResourceParameters rekommendationsResourceParameters) { if (rekommendationsResourceParameters == null) { throw new ArgumentNullException(nameof(rekommendationsResourceParameters)); } var collection = _context.Rekommendations.Include(d => d.TechJobOpening) as IQueryable <Rekommendation>; var techJobOpeningId = rekommendationsResourceParameters.TechJobOpeningId; if (techJobOpeningId != null) { collection = collection.Where(a => a.TechJobOpening.Id.ToString() == techJobOpeningId); } var position = rekommendationsResourceParameters.Position; if (position != null) { collection = collection.Where(a => a.Position.ToString() == position); } var seniority = rekommendationsResourceParameters.Seniority; if (seniority != null) { collection = collection.Where(a => a.Seniority.ToString() == seniority); } var rekommendationStatus = rekommendationsResourceParameters.Status; if (rekommendationStatus != null) { collection = collection.Where(a => a.Status.ToString() == rekommendationStatus); } var hasAlreadyWorkedWithRekommender = rekommendationsResourceParameters.HasAlreadyWorkedWithRekommender; if (hasAlreadyWorkedWithRekommender == true) { collection = collection.Where(a => a.HasAlreadyWorkedWithRekommender); } if (!string.IsNullOrWhiteSpace(rekommendationsResourceParameters.SearchQuery)) { var searchQuery = rekommendationsResourceParameters.SearchQuery.Trim(); collection = collection.Where(a => a.LastName.ToLower().Contains(searchQuery.ToLower())); } if (!string.IsNullOrWhiteSpace(rekommendationsResourceParameters.OrderBy)) { // get property mapping dictionary var rekommendationMappingDictionary = _propertyMappingService.GetPropertyMapping <RekommendationDto, Rekommendation>(); collection = collection.ApplySort(rekommendationsResourceParameters.OrderBy, rekommendationMappingDictionary); } return(await Utils.PagedList <Rekommendation> .Create(collection, rekommendationsResourceParameters.PageNumber, rekommendationsResourceParameters.PageSize)); }
public async Task <IActionResult> GetRekommendations([FromQuery] RekommendationsResourceParameters rekommendationResourceParameters, [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 <RekommendationDto>(rekommendationResourceParameters.Fields)) { _logger.LogInformation($"Property checker did not find on of the Rekommendation resource parameters fields"); return(BadRequest()); } if (!_propertyMappingService.ValidMappingExistsFor <RekommendationDto, Rekommendation> (rekommendationResourceParameters.OrderBy)) { return(BadRequest()); } var rekommendationsFromRepo = await _repository.GetRekommendationsAsync(rekommendationResourceParameters); return(Ok(rekommendationsFromRepo)); }