public ActionResult <IEnumerable <AuthorOutputDto> > GetAllAuthors(
            [FromHeader(Name = "Content-Type")] string mediaType,
            [FromQuery] BasicResourceParameters parameters)
        {
            var parsedMediaType = GetMediaType(mediaType);
            var fullMedia       = FullMedia(parsedMediaType);

            if (CantValidate(parameters, fullMedia) || parsedMediaType is null)
            {
                return(BadRequest());
            }

            var authorsFromRepo = blogRepository.GetAllAuthors(parameters);

            var shapedAuthors = GetShapedAuthors
                                    (authorsFromRepo, parameters.Fields, fullMedia);

            AddPaginationHeader(authorsFromRepo);

            dynamic toReturn = shapedAuthors;

            if (IncludeLinks(parsedMediaType))
            {
                toReturn = GetCollectionWithLinks
                               (authorsFromRepo, shapedAuthors, parameters);
            }

            return(Ok(toReturn));
        }
        public IActionResult GetCommentsForPost(Guid postAuthorId, Guid postId,
                                                [FromQuery] BasicResourceParameters parameters,
                                                [FromHeader(Name = "Content-Type")] string mediaType)
        {
            if (CantValidateParameters(parameters))
            {
                return(BadRequest());
            }

            if (validator.DontMatchRules(parameters, ModelState))
            {
                return(ValidationProblem(ModelState));
            }

            if (AuthorOrPostNotExist(postAuthorId, postId))
            {
                return(NotFound());
            }

            var commentsFromRepo = blogRepository.GetAllComentsForPost(postId, parameters);

            InsertAuthorsInto(commentsFromRepo.ToArray());

            var mappedComments = mapper.Map <IEnumerable <CommentOutputDto> >(commentsFromRepo);
            var shapedComments = properties.ShapeData(mappedComments, parameters.Fields);

            AddPaginationHeader(commentsFromRepo);

            if (IncludeLinks(mediaType))
            {
                var linkedComments = GetCollectionWithLinks
                                         (commentsFromRepo, shapedComments, parameters);
                return(Ok(linkedComments));
            }

            return(Ok(shapedComments));
        }
 private bool CantValidateParameters(BasicResourceParameters parameters)
 {
     return(validator.FieldsAreInvalid <CommentOutputDto>(parameters.Fields) ||
            validator.OrderIsInvalid <Comment, ICommentOutputDto>(parameters.OrderBy));
 }