public bool AddComment(DCommentPostVM commentPostVm) { if (ModelState.IsValid) { Comment comment = new Comment(); comment.UserId = WebSecurity.CurrentUserId; comment.DateCreated = DateTime.Now; comment.Content = commentPostVm.Content; switch (commentPostVm.Type) { case "problem": //comment.MainPostId = commentPostVm.MainPostId; return _commentCommandService.AddCommentForPost((int)commentPostVm.MainPostId, comment); case "Reply": //comment.ReplyId = commentPostVm.ReplyId; return _commentCommandService.AddCommentForReply((int)comment.ReplyId, comment); default: return false; } } else { // ModelState is not valid return false; } }
public bool AddCommentForReply(int replyId, Comment comment) { comment.ReplyId = replyId; //comment.MainPostId = 0; return commentRepository.Insert(comment); }
public void TestGeneralComment() { IProblemCommandService problemCommandService = ObjectFactory.GetInstance<IProblemCommandService>(); IProblemQueryService problemQueryService = ObjectFactory.GetInstance<IProblemQueryService>(); IRepository<Problem> problemRepository = ObjectFactory.GetInstance<IRepository<Problem>>(); bool res; // create test problem Problem problem = ProblemPreaparation.p; // create Comment Comment c = new Comment(); c.Content = "this is an easy comment"; c.DateCreated = DateTime.Now; c.DateModified = DateTime.Now; c.UserId = problem.UserId; res = problemCommandService.AddComment(problem.Id, c); Assert.IsTrue(res); Assert.IsTrue(c.Id > 0); // retrieve comment // Get All Comments IEnumerable<Comment> comments = problemQueryService.GetAllReplyComments(problem.Id, 0, 100); bool isExist = false; foreach (Comment comment in comments) { if (comment.Id == c.Id && comment.Content == c.Content) { isExist = true; break; } } Assert.IsTrue(isExist); // update comment c.Content = "this is a very very hard comment"; c.DateModified = DateTime.Now; res = problemCommandService.UpdateComment(c); //test update comments = problemQueryService.GetAllReplyComments(problem.Id, 0, 100); isExist = false; foreach (Comment comment in comments) { if (comment.Id == c.Id && comment.Content == c.Content && DateTime.Compare(comment.DateModified, comment.DateCreated) > 0) { isExist = true; break; } } Assert.IsTrue(isExist); // delete problem res = problemCommandService.DeleteComment(c); Assert.IsTrue(res); //test update comments = problemQueryService.GetAllReplyComments(problem.Id, 0, 100); isExist = false; foreach (Comment comment in comments) { if (comment.Id == c.Id) { isExist = true; break; } } Assert.IsFalse(isExist); // End Test ProblemPreaparation.CleanUp(); }
public virtual ActionResult AddComment(CommentPostVM commentPostVm) { if (ModelState.IsValid) { Comment comment = new Comment(); comment.UserId = WebSecurity.CurrentUserId; comment.DateCreated = DateTime.Now; comment.Content = commentPostVm.Content; bool res = false; switch (commentPostVm.Type) { case EnumCommentType.QUESTION: //comment.MainPostId = commentPostVm.MainPostId; res = _commentCommandService.AddCommentForPost((int)commentPostVm.MainPostId, comment); break; case EnumCommentType.REPLY: //comment.ReplyId = commentPostVm.ReplyId; res = _commentCommandService.AddCommentForReply((int)commentPostVm.ReplyId, comment); break; default: return null; } if (res) { CommentItemVM commentItemVm = Mapper.Map<Comment, CommentItemVM>(comment); return PartialView("Partials/_CommentItem", commentItemVm); } else { return null; } } // state is not valid return null; }
public bool DeleteComment(Comment comment) { return mainPostCommandService.DeleteComment(comment); }
public bool AddComment(int problemId, Comment comment) { return mainPostCommandService.AddComment(problemId, comment); }
public bool UpdateComment(Comment comment) { return mainPostCommandService.UpdateComment(comment); }
public bool AddComment(int postId, Comment comment) { comment.MainPostId = postId; return commentRepository.Insert(comment); }
public bool UpdateComment(Comment comment) { return commentRepository.Update(comment); }