Example #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);
        }
 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),
         },
     });
 }
        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);
        }
Example #4
0
        public IJsonApiResource GetJsonApiResourceFor(ApplicationUser user = null)
        {
            var resource = new JsonApiUserResource
            {
                Attributes = new JsonApiUserAttributes
                {
                    DisplayName = this.DisplayName,
                },
                Id    = this.Id.ToString(),
                Links = JsonApiUserResource.CreateLinks(this.Id),
            };

            if (!(user is null))
            {
                if (this.Id == user.Id)
                {
                    resource.Attributes.Email    = this.Email.Value;
                    resource.Attributes.UserName = this.UserName;
                }
            }

            return(resource);
        }