public IHttpActionResult AddNewComment(AddCommentBindingModel bindingModel, int postId) { if (bindingModel == null) { return(this.BadRequest("Invalid data!")); } if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var currentUserId = this.UserIdProvider.GetUserId(); var currentUser = this.Data.Users.Find(currentUserId); var post = this.Data.Posts.Find(postId); if (post == null) { return(this.NotFound()); } if (this.HasAuthorization(currentUser, post)) { return(this.BadRequest("Unable to post comment. You can comment only on your friend's posts or post made on their wall.")); } Comment comment = new Comment { Content = bindingModel.CommentContent, PostedOn = DateTime.Now, PostId = postId, AuthorId = currentUserId }; post.Comments.Add(comment); this.Data.SaveChanges(); CommentViewModel commentViewModel = CommentViewModel.ConvertTo(comment, currentUser); return(this.Ok(commentViewModel)); }