public IHttpActionResult Post(PostCommentOnPost comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateCommentService(); if (!service.CommentOnPost(comment)) { return(InternalServerError()); } return(Ok()); }
public bool MakeComment(PostCommentOnPost model) { var entity = new Comment() { UserId = _userId, CommentId = model.CommentId, Text = model.Text, }; using (var ctx = new ApplicationDbContext()) { ctx.Comments.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CommentOnPost(PostCommentOnPost model) { var commentToCreate = new Comment() { CommentId = model.CommentId, Text = model.Text, Author = model.Author, PostId = model.PostId }; using (var ctx = new ApplicationDbContext()) { ctx.Comments.Add(commentToCreate); return(ctx.SaveChanges() == 1); } }