public IHttpActionResult AddComment(int postId, int userId, CommentForCreationDTO model) { if (!ModelState.IsValid) { return(BadRequest()); } var result = _commentRepository.CommentExists(userId, postId); if (result == true) { return(BadRequest("birden fazla yorum ekleyemezsiniz")); } PostComment postComment = new PostComment(); postComment.UserId = userId; postComment.PostId = postId; postComment.Comment = model.Comment; postComment.DateCreated = DateTime.Now; try { _commentRepository.AddCommentByUser(postComment); } catch (Exception) { throw; } return(Ok()); }
public IActionResult AddComment(int postId, int userId, CommentForCreationDTO model) { if (!ModelState.IsValid) { return(BadRequest(Messages.ModelNullOrEmpty)); } var result = _postCommentService.PostCommentExist(userId, postId); if (result.Data == true) { return(BadRequest(Messages.OneCommentToOnePost)); } PostComment postComment = new PostComment() { UserId = userId, PostId = postId, Comment = model.Comment, DateCreated = DateTime.Now }; _postCommentService.Create(postComment); return(Ok()); }