Exemple #1
0
        public IActionResult AddBlogPost([FromBody] BlogPost newBlogPost)
        {
            if (newBlogPost == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createdBlogPost = _blogPostRepository.AddPost(newBlogPost);

            return(Created($"api/blogpost/{newBlogPost.Id}", createdBlogPost));
        }
Exemple #2
0
 public void AddBlogPost(BlogPost blogPost)
 {
     blogPost.Date = DateTime.Now;
     _blogPostRepository.AddPost(blogPost);
     _blogContext.SaveChanges();
 }