예제 #1
0
        public Task <string> CreatePostAsync(BlogPostAddItem post)
        {
            return(Task.Run(async() =>
            {
                var slug = UtilityService.GenerateSlug(post.BlogPost.Title);

                if (await PostExistsAsync(slug))
                {
                    return null;
                }

                var newPostTags = await AddPostTags(slug, post.BlogPost.TagList);

                var newPost = new Entities.Post
                {
                    Slug = slug,
                    Title = post.BlogPost.Title,
                    Description = post.BlogPost.Description,
                    Body = post.BlogPost.Body,
                    PostTags = newPostTags
                };

                dbContext.Posts.Add(newPost);
                dbContext.SaveChanges();

                return slug;
            }));
        }
        public async Task <IActionResult> Post([FromBody] BlogPostAddItem post)
        {
            var slug = await postRepository.CreatePostAsync(post);

            return(Created("Get", new { slug }));
        }