Exemplo n.º 1
0
        public IActionResult GetAuthors([FromQuery] AuthorResourceParameters authorsResourceParameters)
        {
            if (!_propertyCheck.TypeHasProperties <AuthorDto>(authorsResourceParameters.Fields))
            {
                return(BadRequest());
            }

            var x = _manager.GetAuthors(authorsResourceParameters);

            if (x == null)
            {
                return(NotFound());
            }

            var links = CreateLinksForAuthors(authorsResourceParameters, x.HasNext, x.HasPrevious);

            var shapedAuthors = _mapper.Map <IEnumerable <AuthorDto> >(x).ShapeData(authorsResourceParameters.Fields);

            var shapedAuthorsWithLinks = shapedAuthors.Select(author =>
            {
                var authorAsDictionary = author as IDictionary <string, object>;
                var authorLinks        = CreateLinksForAuthor((Guid)authorAsDictionary["Id"], null);
                authorAsDictionary.Add("links", authorLinks);
                return(authorAsDictionary);
            });

            var LinkedCollectionResource = new
            {
                value = shapedAuthorsWithLinks,
                links
            };

            return(Ok(LinkedCollectionResource));
        }
        public IActionResult GetAuthorCollection(
            [FromRoute]
            [ModelBinder(BinderType = typeof(ArrayModelBinder))] IEnumerable <Guid> ids)
        {
            if (ids == null)
            {
                return(BadRequest());
            }
            var authors = _manager.GetAuthors(ids);

            return(Ok(authors));
        }