예제 #1
0
        public ActionResult AddComment(CommentViewModel model)
        {
            _repository.AddComment(_mapper.Map <Comment>(model));
            var comments = _repository.GetCommentsFor(model.PostId);

            return(PartialView("Comments", _mapper.Map <CommentsViewModel>(comments)));
        }
예제 #2
0
        public async Task <IActionResult> Comment(CommentViewModel cvm)
        {
            if (!ModelState.IsValid)
            {
                //return RedirectToAction("Details", new { id = cvm.PostId });
                return(View(cvm.PostId));
            }

            var post = _postRepository.GetPostId(cvm.PostId);

            if (cvm.MainCommentId == 0)
            {
                post.MainComments = post.MainComments ?? new List <MainComment>();
                post.MainComments.Add(new MainComment
                {
                    PostId     = cvm.PostId,
                    Message    = cvm.Message,
                    CreateTime = DateTime.Now
                });
                _postRepository.UpdatePost(post);
            }
            else
            {
                var comment = new SubComment
                {
                    MainCommentId = cvm.MainCommentId,
                    Message       = cvm.Message,
                    CreateTime    = DateTime.Now
                };
                _postRepository.AddComment(comment);
            }
            await _postRepository.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = cvm.PostId }));
        }
예제 #3
0
        public void AddCommentBasic_PostModel_Test()
        {
            var userModel = new UserDetailModel
            {
                Name     = "Dan",
                Email    = "*****@*****.**",
                Password = "******",
            };
            var userTwoModel = new UserDetailModel
            {
                Name     = "Tester",
                Email    = "",
                Password = "",
            };
            var postModel = new PostDetailModel
            {
                Title = "Funguje to",
            };
            var commentModel = new CommentDetailModel
            {
                Content = "aha"
            };

            userModel    = _userRepository.Create(userModel);
            userTwoModel = _userRepository.Create(userTwoModel);
            postModel    = _postRepository.Create(postModel, userModel);
            commentModel = _commentRepository.Create(commentModel, userTwoModel, postModel);

            Assert.Empty(postModel.Comments);

            postModel = _postRepository.AddComment(postModel, commentModel);

            Assert.NotEmpty(postModel.Comments);
            Assert.Single(postModel.Comments);

            postModel = _postRepository.RemoveComment(postModel, commentModel);

            Assert.Empty(postModel.Comments);

            //Teardown
            _postRepository.Delete(postModel.Id);
        }
예제 #4
0
 public void Put([FromBody] SimpleComment value)
 {
     _repo.AddComment(new Comment()
     {
         Id     = new Guid(),
         Author = value.Author,
         Body   = value.Body,
         PostId = value.PostId
     });
     Console.WriteLine(value);
 }
예제 #5
0
 public void AddComment(int postId, string name, string comment)
 {
     try
     {
         _postRepository.AddComment(postId, name, comment);
     }
     catch (Exception e)
     {
         throw new MBlogException("Unable to add comment", e);
     }
 }
예제 #6
0
        public void CreateComment(object obj)
        {
            Comment.Time = DateTime.Now;

            Comment = postRepository.CreateComment(Comment, User.Id);
            Post    = postRepository.AddComment(Post.Id, Comment.Id);

            mediator.Send(new ActiveTeamMessage {
                Id = Team.Id
            });
            infoText = "Comment successfully created";
        }
예제 #7
0
        public void GetActivitiesByIdTest()
        {
            //Arrange
            var teamModel = _teamRepository.Create(new TeamDetailModel
            {
                Name = "TestTeam"
            });

            var userOneModel = _userRepository.Create(new UserDetailModel
            {
                Name     = "User One",
                Email    = "*****@*****.**",
                Password = "******"
            });

            var postModel = _postRepository.Create(new PostDetailModel
            {
                Content = "ContentOfPostOne",
                Title   = "TitleOfPostOne"
            },
                                                   userOneModel);

            teamModel = _teamRepository.AddPost(teamModel, postModel);

            var commentOne = _commentRepository.Create(new CommentDetailModel
            {
                Content = "CommentOfPostOne"
            },
                                                       userOneModel,
                                                       postModel);

            postModel = _postRepository.AddComment(postModel, commentOne);
            //Act
            var activities = _userRepository.GetActivitiesById(userOneModel.Id);

            //Assert
            Assert.NotNull(activities);
            //Teardown
            if (commentOne != null)
            {
                _commentRepository.Delete(commentOne.Id);
            }
            if (postModel != null)
            {
                _postRepository.Delete(postModel.Id);
            }
            if (userOneModel != null)
            {
                _userRepository.Delete(userOneModel.Id);
            }
            if (teamModel != null)
            {
                _teamRepository.Delete(teamModel.Id);
            }
        }
예제 #8
0
        public ActionResult AddComment(int?parentId, int postId, string UserId, string Text)
        {
            if (Text != null)
            {
                repository.AddComment(parentId, postId, UserId, Text);
            }
            else
            {
                TempData["Required field"] = "Required field";
            }

            return(RedirectToAction("ShowPost", new { id = postId }));
        }
예제 #9
0
        public async Task <IActionResult> AddComment(int postId, Comment comment)
        {
            if (postId == 0)
            {
                return(NotFound());
            }

            comment.User = User.Identity.Name ?? "guest";

            await postRepository.AddComment(postId, comment);

            return(RedirectToAction(nameof(Index)));
        }
예제 #10
0
        private Task AddCommentAsync(Guid postId)
        {
            return(Task.Run(() =>
            {
                var post = _postRepository.GetById(postId);

                var comment = new CommentDetailModel();
                comment.Content = Content;

                var returnedComment = _commentRepository.Create(comment, CurrentUser, post);

                _postRepository.AddComment(post, returnedComment);
            }));
        }
        public ActionResult Create(CreateCommentModel model)
        {
            _postRepository.AddComment(
                model.Content, model.UserName,
                model.ReturnBlogSlug, model.ReturnPostSlug
                );

            return(RedirectToAction("Details", "Post",
                                    new
            {
                blogSlug = model.ReturnBlogSlug,
                postSlug = model.ReturnPostSlug
            }));
        }
예제 #12
0
        public ActionResult AddComment(ViewPostModel vpm)
        {
            if (User.Identity.IsAuthenticated)
            {
                vpm.Comment.Email = "RegisteredUser@" + User.Identity.Name + ".com";
                vpm.Comment.User  = User.Identity.Name;
            }
            vpm.Comment.Date = DateTime.Now;

            if (ModelState.IsValid)
            {
                repository.AddComment(vpm.Comment);
                repository.SaveChanges();
            }
            return(RedirectToAction("FullPost", new { vpm.Comment.PostId }));
        }
예제 #13
0
        public IActionResult ComposeComment(PostViewModel model, int id)
        {
            var token = HttpContext.Request.Cookies["user-token"];

            var myprofile = _profileRepository.GetUserByToken(token);


            if (ModelState.IsValid)
            {
                Comment comment = new Comment
                {
                    Text      = model.Comment.Text,
                    AddedDate = DateTime.Now,
                    UserId    = myprofile.Id,
                    PostId    = id
                };

                _postRepository.AddComment(comment);

                return(RedirectToAction("index", new { id = id }));
            }
            return(Ok(model));
        }
예제 #14
0
        public string Get(string setting)
        {
            Post post1 = new Post()
            {
                Id    = new Guid(),
                Title = "Post title 1",
                Body  = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem " +
                        "accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab " +
                        "illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. " +
                        "Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed " +
                        "quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque " +
                        "porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci " +
                        "velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam " +
                        "aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem " +
                        "ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?",
                PublicationDate = DateTime.Now,
                LastModified    = DateTime.Now
            };



            if (setting == "initialize")
            {
                _repository.AddPost(post1);

                _repository.AddComment(new Comment()
                {
                    Id          = new Guid(),
                    Author      = "Peppe",
                    Body        = "This post is lame!",
                    PostId      = post1.Id,
                    CommentedOn = DateTime.Now
                });

                _repository.AddComment(new Comment()
                {
                    Id          = new Guid(),
                    Author      = "Salvo",
                    Body        = "Bla bla bla bla bla",
                    PostId      = post1.Id,
                    CommentedOn = DateTime.Now
                });
                _repository.AddPost(new Post()
                {
                    Id              = new Guid(),
                    Title           = "Post title 2",
                    Body            = "Test body 2",
                    PublicationDate = DateTime.Now,
                    LastModified    = DateTime.Now
                });
                _repository.AddPost(new Post()
                {
                    Id              = new Guid(),
                    Title           = "Post title 3",
                    Body            = "Test body 3",
                    PublicationDate = DateTime.Now,
                    LastModified    = DateTime.Now
                });
                _repository.AddPost(new Post()
                {
                    Id              = new Guid(),
                    Title           = "Post title 4",
                    Body            = "Test body 4",
                    PublicationDate = DateTime.Now,
                    LastModified    = DateTime.Now
                });

                return("Done");
            }

            return("Unknown");
        }
예제 #15
0
 public void CreateComment()
 {
     Post = repository.AddComment(Post.Id, Comment.Id);
 }
예제 #16
0
 public async Task AddComment(string postId, Comment comment)
 {
     await _repository.AddComment(postId, comment);
 }
예제 #17
0
        public void AddCommentToPostInTeam_Integration_Test()
        {
            // Arrange
            // Team creation
            var teamModel = _teamRepository.Create(new TeamDetailModel
            {
                Name = "TestTeam"
            });

            var userOneModel = _userRepository.Create(new UserDetailModel
            {
                Name     = "User One",
                Email    = "*****@*****.**",
                Password = "******"
            });
            var userTwoModel = _userRepository.Create(new UserDetailModel
            {
                Name     = "User Two",
                Email    = "*****@*****.**",
                Password = "******"
            });

            teamModel = _teamRepository.AddMember(teamModel, userOneModel);
            teamModel = _teamRepository.AddMember(teamModel, userTwoModel);

            // Update users teams
            userOneModel = _userRepository.GetById(userOneModel.Id);
            userTwoModel = _userRepository.GetById(userTwoModel.Id);

            // Post creation
            var postModelOne = _postRepository.Create(new PostDetailModel
            {
                Content = "ContentOfPostOne",
                Title   = "TitleOfPostOne"
            },
                                                      userOneModel);

            teamModel = _teamRepository.AddPost(teamModel, postModelOne);

            // Comment creation
            var commentOne = _commentRepository.Create(new CommentDetailModel
            {
                Content = "CommentOfPostOne"
            },
                                                       userOneModel,
                                                       postModelOne);

            postModelOne = _postRepository.AddComment(postModelOne, commentOne);

            var commentTwo = _commentRepository.Create(new CommentDetailModel
            {
                Content = "2CommentOfPostTwo"
            },
                                                       userTwoModel,
                                                       postModelOne);

            postModelOne = _postRepository.AddComment(postModelOne, commentTwo);

            var commentThree = _commentRepository.Create(new CommentDetailModel
            {
                Content = "3rdCommentOfPostTwo"
            },
                                                         userOneModel,
                                                         postModelOne);

            postModelOne = _postRepository.AddComment(postModelOne, commentThree);

            var postModelTwo = _postRepository.Create(new PostDetailModel
            {
                Content = "ContentOfPostTwo",
                Title   = "TitleOfPostTwo"
            },
                                                      userTwoModel);

            // Updated team model with comments
            teamModel = _teamRepository.GetById(teamModel.Id);

            // Updated user with activities
            userOneModel = _userRepository.GetById(userOneModel.Id);


            Assert.Equal(3, postModelOne.Comments.Count);
            Assert.Equal(3, userOneModel.Activities.Count);
            postModelOne = _postRepository.RemoveComment(postModelOne, commentOne);
            _commentRepository.Delete(commentOne);
            Assert.Equal(2, postModelOne.Comments.Count);

            userOneModel = _userRepository.GetById(userOneModel.Id);
            Assert.Equal(2, userOneModel.Activities.Count);


            _commentRepository.Delete(commentTwo);
            _commentRepository.Delete(commentThree);
            _postRepository.Delete(postModelOne);

            userOneModel = _userRepository.GetById(userOneModel.Id);
            Assert.Equal(0, userOneModel.Activities.Count);

            teamModel = _teamRepository.RemoveMember(teamModel, userOneModel);
            Assert.Equal(1, teamModel.Members.Count);

            userOneModel = _userRepository.GetById(userOneModel.Id);
            Assert.Equal(0, userOneModel.Teams.Count);
        }