public IHttpActionResult Post(PostAPost model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreatePostService(); if (!service.CreatePost(model)) { return(InternalServerError()); } return(Ok()); }
public bool CreatePost(PostAPost model) { var postToCreate = new Post() { UserId = _userId, Title = model.Title, Text = model.Text, }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(postToCreate); return(ctx.SaveChanges() == 1); } }
// Posting a Post public bool CreatePost(PostAPost model) { var entity = new Post() { AuthorId = _userId, Title = model.Title, Text = model.Text }; using (var ctx = new ApplicationDbContext()) { ctx.Posts.Add(entity); return(ctx.SaveChanges() == 1); } }