public static JToken ToJson(BaseComment c) { var obj = (JObject)ToJson((Entry)c); obj["content"] = c.Content; return(obj); }
public IHttpActionResult PostComment(BaseComment commentData) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApplicationUser currentUser = db.Users.Find(User.Identity.GetUserId()); Post currentPost = db.Posts.Find(commentData.PostId); Comment newComment = new Comment { Post = currentPost, Content = commentData.Content, Author = (currentUser == null) ? "Anonymus" : currentUser.UserName, Engagement = new Engagement { Likes = 0 } }; currentPost.Comments.Add(newComment); try { db.Comments.Add(newComment); db.SaveChanges(); } catch (Exception E) { return(BadRequest("Not done")); } return(StatusCode(HttpStatusCode.OK)); }
public static BaseComment Convert(this Comment model, IMapper _mapper) { BaseComment comment = _mapper.Map <Comment, BaseComment>(model); comment.Date = model.DatePosted.ToShortDateString(); comment.Time = model.DatePosted.ToShortTimeString(); return(comment); }
public IHttpActionResult Like(BaseComment currentComment) { Comment comment = db.Comments.Find(currentComment.CommentId); ApplicationUser currentUser = db.Users.Find(User.Identity.GetUserId()); comment.LikedBy.Add(currentUser); comment.Engagement.Likes += 1; currentUser.LikedComments.Add(comment); db.SaveChanges(); return(StatusCode(HttpStatusCode.OK)); }