public async Task <IActionResult> GetTagsAsync() { var responseDocument = new JsonApiMultiResourceDocument(); var allTags = await this.tagManager.Store.QueryableTags.ToListAsync(); responseDocument.Data = allTags.Select(x => JsonApiTagResource.Create(x) as IJsonApiResourceIdentifier).ToList(); return(this.Ok(responseDocument)); }
public async Task <IActionResult> CreateTagAsync([FromBody] JsonApiTagDocument requestDocument) { var responseDocument = new JsonApiDocument(); if (requestDocument is null || requestDocument.Data is null || requestDocument.Data.Attributes is null || string.IsNullOrWhiteSpace(requestDocument.Data.Attributes.Name)) { return(this.BadRequest(requestDocument)); } var tag = requestDocument.Data.CreateDatabaseModel(); tag.Id = ObjectId.GenerateNewId(); await this.tagManager.CreateAsync(tag); requestDocument.Data = JsonApiTagResource.Create(tag); return(this.Ok(requestDocument)); }
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); }