示例#1
0
        ICollection <CommentGetDto> ICommentBusinessLogic.GetAll(Guid postId, UserInfoModel userInfo)
        {
            ICollection <Comment>       comments         = commentRepository.GetAllByFilter(c => c.PostId == postId, "Reacts");
            ICollection <CommentGetDto> returnedComemnts = new List <CommentGetDto>();

            foreach (Comment comment in comments)
            {
                CommentGetDto commentGetDto = mapper.Map <CommentGetDto>(comment);
                if (userInfo != null && comment.Reacts != null)
                {
                    CommentReact react = comment.Reacts.FirstOrDefault(cr => cr.UserId == userInfo.CreatorId);
                    if (react != null)
                    {
                        if (react.Type == ReactType.Like)
                        {
                            commentGetDto.Liked = true;
                        }
                        else if (react.Type == ReactType.Dislike)
                        {
                            commentGetDto.Disliked = true;
                        }
                    }
                }
                returnedComemnts.Add(commentGetDto);
            }

            return(returnedComemnts);
        }
        public CommentGetDto Execute(int id)
        {
            var comment = _context.Comments.Find(id);

            if (comment == null)
            {
                throw new EntityNotFoundException(id, typeof(Comment));
            }

            var blog    = _context.Blogs.Find(comment.BlogId);
            var blogDto = new BlogGetDto
            {
                Id   = blog.Id,
                Name = blog.Name
            };

            var user    = _context.Users.Find(comment.UserId);
            var userDto = new UserGetDto
            {
                Id       = user.Id,
                Username = user.UserName
            };

            var result = new CommentGetDto
            {
                Id       = comment.Id,
                Text     = comment.Text,
                UserId   = userDto.Id,
                Username = userDto.Username,
                BlogId   = blogDto.Id,
                Name     = blogDto.Name
            };

            return(result);
        }
示例#3
0
        public void GetById_ReturnsCreatedInstance()
        {
            //Arrange
            commentRepositoryMock.Setup(x => x.GetById(testComment.Id)).Returns(testComment);

            //Act
            CommentGetDto returnedComment = systemUnderTest.GetById(testComment.Id);

            //Assert
            Assert.True(testCommentGetDto.Id.Equals(returnedComment.Id));
            Assert.True(testCommentGetDto.PostId.Equals(returnedComment.PostId));
            Assert.True(testCommentGetDto.Text.Equals(returnedComment.Text));
        }