コード例 #1
0
ファイル: DiscussionController.cs プロジェクト: hqt/MathHub
        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;
            }
        }
コード例 #2
0
ファイル: CommentCommandService.cs プロジェクト: hqt/MathHub
 public bool AddCommentForReply(int replyId, Comment comment)
 {
     comment.ReplyId = replyId;
     //comment.MainPostId = 0;
     return commentRepository.Insert(comment);
 }
コード例 #3
0
ファイル: CommentTest.cs プロジェクト: hqt/MathHub
        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();
        }
コード例 #4
0
ファイル: ProblemAJAXController.cs プロジェクト: hqt/MathHub
        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;
        }
コード例 #5
0
ファイル: ProblemCommandService.cs プロジェクト: hqt/MathHub
 public bool DeleteComment(Comment comment)
 {
     return mainPostCommandService.DeleteComment(comment);
 }
コード例 #6
0
ファイル: ProblemCommandService.cs プロジェクト: hqt/MathHub
 public bool AddComment(int problemId, Comment comment)
 {
     return mainPostCommandService.AddComment(problemId, comment);
 }
コード例 #7
0
ファイル: ProblemCommandService.cs プロジェクト: hqt/MathHub
 public bool UpdateComment(Comment comment)
 {
     return mainPostCommandService.UpdateComment(comment);
 }
コード例 #8
0
ファイル: MainPostCommandService.cs プロジェクト: hqt/MathHub
 public bool AddComment(int postId, Comment comment)
 {
     comment.MainPostId = postId;
     return commentRepository.Insert(comment);
 }
コード例 #9
0
ファイル: MainPostCommandService.cs プロジェクト: hqt/MathHub
 public bool UpdateComment(Comment comment)
 {
     return commentRepository.Update(comment);
 }