Exemplo n.º 1
0
        public Document GetBlogToArticles(string id)
        {
            /////////////////////////////////////////////////////
            // Get Blog to related Articles by Blog identifier from repository
            /////////////////////////////////////////////////////
            var blogToArticles = BloggingRepository.GetBlogToArticles(Convert.ToInt64(id));

            /////////////////////////////////////////////////////
            // Build JSON API document
            /////////////////////////////////////////////////////
            var currentRequestUri = this.Request.GetUri();

            using (var documentContext = new BloggingDocumentContext(currentRequestUri))
            {
                var document = documentContext
                               .NewDocument(currentRequestUri)
                               .SetJsonApiVersion(JsonApiVersion.Version10)
                               .Links()
                               .AddUpLink()
                               .AddSelfLink()
                               .LinksEnd()
                               .ResourceCollection(blogToArticles)
                               .Relationships()
                               .AddRelationship("blog", new[] { Keywords.Related })
                               .AddRelationship("comments", new[] { Keywords.Related })
                               .RelationshipsEnd()
                               .Links()
                               .AddSelfLink()
                               .LinksEnd()
                               .ResourceCollectionEnd()
                               .WriteDocument();

                return(document);
            }
        }