public IActionResult GetAuthors([FromQuery] AuthorsResourceParameters parameters, [FromHeader(Name = Headers.Accept)] string mediaType) { if (!_propertyMappingService.ValidMappingExistsFor <Author, Entities.Author>(parameters.OrderBy)) { return(BadRequest()); } if (!_typeHelperService.TypeHasProperties <Author>(parameters.Fields)) { return(BadRequest()); } var authors = _repo.GetAuthors(parameters); var currentMediaType = new MediaType(mediaType); var includeLinks = currentMediaType.IsSubsetOf(VendorMediaType.HateoasLinksMediaType); var prev = authors.HasPrevious ? CreateAuthorsResourceUri(parameters, ResourceUriType.Previous) : null; var next = authors.HasNext ? CreateAuthorsResourceUri(parameters, ResourceUriType.Next) : null; var result = Mapper.Map <IEnumerable <Author> >(authors); var pagination = new Pagination() { IncludeLinks = !includeLinks, TotalCount = authors.TotalCount, PageSize = authors.PageSize, CurrentPage = authors.CurrentPage, TotalPages = authors.TotalPages, NextPageLink = next, PreviousPageLink = prev, }; Pagination.AddHeader(Response, pagination); if (includeLinks) { var links = CreateLinks(parameters, authors.HasNext, authors.HasPrevious); var shapedAuthors = result.ShapeData(parameters.Fields); var shapedAuthorsWithLinks = shapedAuthors.Select(a => { var authorDictionary = a as IDictionary <string, object>; var authorLinks = CreateLinks((Guid)authorDictionary[nameof(Author.Id)], parameters.Fields); authorDictionary.Add("links", authorLinks); return(authorDictionary); } ); var linkCollection = new { value = shapedAuthorsWithLinks, links }; return(Ok(linkCollection)); } return(Ok(result)); }