Ejemplo n.º 1
0
        public static JsonApiTopicInfoResource Create(ForumPost topic)
        {
            var resource = new JsonApiTopicInfoResource
            {
                Attributes = new JsonApiTopicInfoAttributes
                {
                    Created    = topic.Id.CreationTime,
                    Statistics = new JsonApiTopicInfoStatisticsAttribute
                    {
                        CommentCount  = topic.Statistics.CommentCount,
                        DownvoteCount = topic.Statistics.DownvoteCount,
                        PostCount     = topic.Statistics.PostCount,
                        UpvoteCount   = topic.Statistics.UpvoteCount
                    },
                    Title   = topic.Title,
                    Type    = topic.Type,
                    Updated = topic.DateLastModified?.DateTimeOffset.UtcDateTime
                },
                Id            = topic.Id.ToString(),
                Links         = CreateLinks(topic.Id),
                Relationships = new JsonApiTopicInfoRelationships
                {
                    Owner = JsonApiUserResource.CreateRelationship(topic.OwnerId),
                },
            };

            return(resource);
        }
Ejemplo n.º 2
0
 public static JsonApiSessionResource Create(ApplicationUser user)
 {
     return(new JsonApiSessionResource
     {
         Attributes = new JsonApiSessionAttributes
         {
             Email = user.Email.Value,
         },
         Id = ObjectId.GenerateNewId().ToString(),
         Relationships = new JsonApiSessionRelationships
         {
             User = JsonApiUserResource.CreateRelationship(user.Id),
         },
     });
 }
Ejemplo n.º 3
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);
        }