Ejemplo n.º 1
0
        public static JsonApiPostResource Create(ForumPost post)
        {
            var resource = new JsonApiPostResource
            {
                Attributes = new JsonApiPostAttributes
                {
                    Body       = post.Body,
                    Created    = post.Id.CreationTime,
                    Statistics = new JsonApiPostStatisticsAttribute
                    {
                        CommentCount  = post.Statistics.CommentCount,
                        DownvoteCount = post.Statistics.DownvoteCount,
                        UpvoteCount   = post.Statistics.UpvoteCount
                    },
                    Title   = post.Title,
                    Type    = post.Type,
                    Updated = post.DateLastModified?.DateTimeOffset.UtcDateTime,
                },
                Id            = post.Id.ToString(),
                Links         = CreateLinks(post.Id),
                Relationships = new JsonApiPostRelationships
                {
                    Owner = JsonApiUserResource.CreateRelationship(post.OwnerId),
                },
            };

            if (post.ParentId != default)
            {
                resource.Relationships.Parent = JsonApiTopicInfoResource.CreateRelationship(post.ParentId);
            }

            if (post.Tags != null && post.Tags.Count > 0)
            {
                resource.Relationships.Tags = JsonApiTagResource.CreateRelationshipMany(post.Tags);
            }

            return(resource);
        }