示例#1
0
        public Document Get(string id)
        {
            /////////////////////////////////////////////////////
            // Get Blog by identifier from repository
            /////////////////////////////////////////////////////
            var blog = BloggingRepository.GetBlog(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()
                               .Resource(blog)
                               .Relationships()
                               .AddRelationship("articles", new[] { Keywords.Related })
                               .RelationshipsEnd()
                               .Links()
                               .AddSelfLink()
                               .LinksEnd()
                               .ResourceEnd()
                               .WriteDocument();

                return(document);
            }
        }