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)); }
public void AddBlogPost(BlogPost blogPost) { blogPost.Date = DateTime.Now; _blogPostRepository.AddPost(blogPost); _blogContext.SaveChanges(); }