Пример #1
0
        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));
        }
Пример #2
0
        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));
        }