public ActionResult DeleteReply(int id) { Comment comment = new Comment(); CommentRepository commentRepository = new CommentRepository(); comment = commentRepository.GetById(id); commentRepository.Delete(comment); return RedirectToAction("Articles"); }
public JsonResult Reply(int commentId, int replyId, string content) { CommentRepository commentRepository = new CommentRepository(); Comment comment = new Comment(); Comment replyComment = new Comment(); if (replyId == 0) { comment = commentRepository.GetById(commentId); replyComment.Article = comment.Article; replyComment.ArticleID = comment.ArticleID; replyComment.DateCreated = DateTime.Now; replyComment.UserID = AuthenticationManager.LoggedUser.Id; replyComment.Content = content; replyComment.ParentComment = comment; string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString(); int start = type.LastIndexOf(".") + 1; int positions = type.Length - start; type = type.Substring(start, positions); replyComment.UserType = type; commentRepository.Save(replyComment); } if (commentId == 0) { comment = commentRepository.GetById(replyId); comment.Content = content; comment.DateCreated = DateTime.Now; string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString(); int start = type.LastIndexOf(".") + 1; int positions = type.Length - start; type = type.Substring(start, positions); comment.UserType = type; commentRepository.Save(comment); } SelectListItem item = new SelectListItem() { Text = commentId.ToString(), Value = comment.Article.Id.ToString() }; return Json(item, JsonRequestBehavior.AllowGet); }
public JsonResult Comment(int articleId, int commentId, string content) { ArticleRepository articleRepository = new ArticleRepository(); CommentRepository commentRepository = new CommentRepository(); Article article = new Article(); Comment comment = new Comment(); article = articleRepository.GetById(articleId); if (commentId == 0) { comment.ArticleID = articleId; comment.Content = content; comment.DateCreated = DateTime.Now; comment.UserID = AuthenticationManager.LoggedUser.Id; string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString(); int start = type.LastIndexOf(".") + 1; int positions = type.Length - start; type = type.Substring(start, positions); comment.UserType = type; } else { comment = commentRepository.GetById(commentId); comment.Content = content; comment.DateCreated = DateTime.Now; string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString(); int start = type.LastIndexOf(".") + 1; int positions = type.Length - start; type = type.Substring(start, positions); comment.UserType = type; } commentRepository.Save(comment); string comentator = AuthenticationManager.LoggedUser.FirstName + " " + AuthenticationManager.LoggedUser.LastName; SelectListItem commentContent = new SelectListItem() { Text = comment.Content, Value = comentator }; return Json(commentContent, JsonRequestBehavior.AllowGet); }