Example #1
0
 public ActionResult AddComment(string content, string userId, string ariticleId, string comment_temp)
 {
    
     CommentRepository cr = new CommentRepository();
     UserRepository ur = new UserRepository();
     string result = "";
     if (comment_temp != "null")
     {
         string[] array = comment_temp.Split('#');
         int id = Int32.Parse(array[0]);
         string firstUserId = array[1];
         Comment c = cr.FindByID(id);
         User u = ur.FindByID(userId);
         User firstUser = ur.FindByID(firstUserId);
         c.Isleaf = 1;
         cr.Update(c);
         Comment comment = new Comment();
         comment.UserId = userId;
         comment.AriticleId = ariticleId;
         comment.Content = content;
         comment.NickName = u.NickName;
         comment.FirstNickName = firstUser.NickName;
         comment.Pid = id;
         comment.Isleaf = 0;
         comment.CommentTime = DateTime.Now;
         cr.Add(comment);
         result = "";
         result = JsonConvert.SerializeObject(comment);
     }
     else {
         User u = ur.FindByID(userId);
         Comment comment = new Comment();
         comment.UserId = userId;
         comment.Content = content;
         comment.CommentTime = DateTime.Now;
         comment.AriticleId = ariticleId;
         comment.Pid = 0;
         comment.Isleaf = 0;
         comment.Level = 1;
         comment.NickName = u.NickName;
         comment.FirstNickName = null;
         cr.Add(comment);
         result = "";
         result = JsonConvert.SerializeObject(comment);
         ;
     }
     return Content(result);
 }
Example #2
0
 public List<Comment> ReadComments(List<Comment> comments, int id, int level)
 {
     //List<Comment> comments = new List<Comment>();
     List<Comment> newComments = GetCommentChidren(id);
     for (int i = 0; i < newComments.Count; i++) {
         Comment comment = new Comment();
         comment = toComment(newComments[i]);
         comments.Add(comment);
         if (comment.Isleaf == 1) {
             ReadComments(comments,comment.Id, level + 1);
         }
     }
     return comments;
     //string result = JsonConvert.SerializeObject(comments);
     //return Content(result);
 }
Example #3
0
 public Comment toComment(Comment c) {
     Comment comment = new Comment();
     comment.Id = c.Id;
     comment.AriticleId = c.AriticleId;
     comment.CommentTime = c.CommentTime;
     comment.Content = c.Content;
     comment.Isleaf =c.Isleaf;
     comment.UserId = c.UserId;
     comment.Pid = c.Pid;
     comment.Level = c.Level;
     comment.NickName = c.NickName;
     comment.FirstNickName = c.FirstNickName;
     return comment;
 }