public ActionResult NewComment(string commentBody, string comUserName, string slug, string postid) { List<int> numlist = new List<int>(); int num = 0; var comments = _blogRepository.GetComments().ToList(); if (comments.Count() != 0) { foreach (var cmnt in comments) { var comid = cmnt.Id; Int32.TryParse(comid.Replace("cmt", ""), out num); numlist.Add(num); } numlist.Sort(); num = numlist.Last(); num++; } else { num = 1; } var newid = "cmt" + num.ToString(); var comment = new Comment() { Id = newid, PostId = postid, DateTime = DateTime.Now, UserName = comUserName, Body = commentBody, NetLikeCount = 0 }; _blogRepository.AddNewComment(comment); return RedirectToAction("Post", new { slug = slug }); }
public string[] CommentDetails(Comment comment) { string[] commentDetails = new string[17]; commentDetails[0] = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(comment.UserName);//username commentDetails[1] = "/Content/images/profile/" + commentDetails[0] + ".png?time=" + DateTime.Now.ToString();//imgUrl commentDetails[2] = TimePassed(comment.DateTime);//passed time commentDetails[3] = comment.DateTime.ToLongDateString().Replace(comment.DateTime.DayOfWeek.ToString() + ", ", "");//comment date commentDetails[4] = "gp" + comment.Id; //grandparentid commentDetails[5] = "mc" + comment.Id; //maincommentId commentDetails[6] = "crp" + comment.Id; //repliesId commentDetails[7] = "cex" + comment.Id; //commentExpid commentDetails[8] = "ctex" + comment.Id; //ctrlExpId commentDetails[9] = "ctflg" + comment.Id; //ctrlFlagId commentDetails[10] = "sp" + comment.Id; //shareParentId commentDetails[11] = "sc" + comment.Id; //shareChildId commentDetails[12] = "td" + comment.Id; //comText commentDetails[13] = "tdc" + comment.Id; //comTextdiv commentDetails[14] = "rpl" + comment.Id; //Reply commentDetails[15] = "cc1" + comment.Id; //commentControl commentDetails[16] = "cc2" + comment.Id; //commentMenu return commentDetails; }
public void AddNewComment(Comment comment) { _context.Comments.Add(comment); Save(); }
public CommentViewModel(Comment comment) { Comment = comment; }
public List<CommentViewModel> GetParentReplies(Comment comment) { var parentReplies = _context.Replies.Where(p => p.CommentId == comment.Id && p.ParentReplyId == null).ToList(); List<CommentViewModel> parReplies = new List<CommentViewModel>(); foreach (var pr in parentReplies) { var chReplies = GetChildReplies(pr); parReplies.Add(new CommentViewModel() { Body = pr.Body, ParentReplyId = pr.ParentReplyId, DateTime = pr.DateTime, Id = pr.Id, UserName = pr.UserName, ChildReplies = chReplies }); } return parReplies; }