public ActionResult <IEnumerable <WaterProfileDto> > GetWaterProfiles( [FromQuery] WaterProfileResourceParameters waterProfileResourceParameters, [FromHeader(Name = ExtendedControllerBase.ACCEPT)] string mediaTypes) { if (!_propertyMappingService.ValidMappingExistsFor <WaterProfileDto, Entities.WaterProfile> (waterProfileResourceParameters.OrderBy)) { return(BadRequest()); } var splitMediaTypes = mediaTypes.Split(','); if (!MediaTypeHeaderValue.TryParseList(splitMediaTypes, out IList <MediaTypeHeaderValue> parsedMediaTypes)) { return(BadRequest()); } var waterProfiles = _homeBrewRepository.GetWaterProfiles(waterProfileResourceParameters); var paginationMetaData = new { totalCount = waterProfiles.TotalCount, pageSize = waterProfiles.PageSize, currentPage = waterProfiles.CurrentPage, totalPages = waterProfiles.TotalPages }; Response.Headers.Add(this.PAGINATION_HEADER, JsonSerializer.Serialize(paginationMetaData)); var shapedWaterProfiles = _mapper.Map <IEnumerable <WaterProfileDto> >(waterProfiles). ShapeData(null); if (parsedMediaTypes.Any(pmt => pmt.SubTypeWithoutSuffix.EndsWith(this.HATEOAS, StringComparison.InvariantCultureIgnoreCase))) { var links = CreateLinksForWaterProfiles(waterProfileResourceParameters, waterProfiles.HasNext, waterProfiles.HasPrevious); var shapedWaterProfilesWithLinks = shapedWaterProfiles.Select(waterProfile => { var waterProfileAsDictionary = waterProfile as IDictionary <string, object>; var waterProfileLinks = CreateLinksForWaterProfile((int)waterProfileAsDictionary["Id"], false); waterProfileAsDictionary.Add(this.LINKS, links); return(waterProfileAsDictionary); }); var linkedCollectionResource = new { value = shapedWaterProfilesWithLinks, links }; return(Ok(linkedCollectionResource)); } return(Ok(shapedWaterProfiles)); }