Exemplo n.º 1
0
        private IEnumerable <CommentData> GetComments(CommentsResult result, bool registered)
        {
            Total = result.Data.GetCommentsByConfig.ArticleEntity.CountTotal;
            foreach (var comment in result.Data.GetCommentsByConfig.ArticleEntity.Comments)
            {
                var commentData = new CommentData();
                commentData.AdditionalData  = comment;
                commentData.Id              = comment?.Id.ToString();
                commentData.Author          = comment?.Author?.DisplayName;
                commentData.AuthorId        = comment?.Author?.Id.ToString();
                commentData.IsSpecialAuthor = registered;
                if (comment != null)
                {
                    commentData.Date = comment.CreatedTime.DateTime;
                    if (comment.Reaction != null)
                    {
                        commentData.Positive = comment.Reaction.Where(item => string.Compare(item.Reaction, "Like", StringComparison.OrdinalIgnoreCase) == 0).Sum(item => item.Count);
                        commentData.Negative = comment.Reaction.Where(item => string.Compare(item.Reaction, "Dislike", StringComparison.OrdinalIgnoreCase) == 0).Sum(item => item.Count);
                    }
                }

                commentData.Text = comment?.Content;
                yield return(commentData);
            }
        }
Exemplo n.º 2
0
        private void ReplyClick(object sender, RoutedEventArgs e)
        {
            CommentsResult result = (sender as Button).Tag as CommentsResult;

            ReplyTarget = new Tuple <string, string>(result.User.Nickname, result.User.Slug);

            FillCommentTextBox(ReplyTarget);
        }
Exemplo n.º 3
0
 public static CommentsDto FromResult(CommentsResult result)
 {
     return(new CommentsDto
     {
         CreatedComments = result.CreatedComments.Select(CommentDto.FromComment).ToArray(),
         UpdatedComments = result.UpdatedComments.Select(CommentDto.FromComment).ToArray(),
         DeletedComments = result.DeletedComments,
         Version = result.Version
     });
 }
Exemplo n.º 4
0
        public static CommentsDto FromDomain(CommentsResult comments)
        {
            var result = new CommentsDto
            {
                CreatedComments = comments.CreatedComments.Select(CommentDto.FromDomain).ToArray(),
                UpdatedComments = comments.UpdatedComments.Select(CommentDto.FromDomain).ToArray(),
                DeletedComments = comments.DeletedComments,
                Version         = comments.Version
            };

            return(result);
        }
Exemplo n.º 5
0
        public CommentsResult Get()
        {
            var vm       = new CommentsResult();
            var comments = _ctx.Comments.Include(m => m.Author).ToList();
            var items    = new List <CommentItem>();

            foreach (var c in comments)
            {
                items.Add(_jsonService.GetComment(c, comments));
            }
            vm.Items        = items;
            vm.Detail       = new CommentDetail();
            vm.SelectedItem = new CommentItem();
            return(vm);
        }
        public async Task ItShouldReturnComments()
        {
            var expectedResult = new CommentsResult(
                new List <CommentsResult.Item>
            {
                new CommentsResult.Item(CommentId.Random(), PostId.Random(), UserId.Random(), new Username("blah"), new Comment("comment"), DateTime.UtcNow),
            });

            this.getComments.Setup(v => v.ExecuteAsync(PostId))
            .Returns(Task.FromResult(expectedResult))
            .Verifiable();

            var result = await this.target.HandleAsync(new GetCommentsQuery(Requester, PostId, Timestamp));

            Assert.AreEqual(expectedResult, result);
            this.getComments.Verify();
        }
Exemplo n.º 7
0
        public async Task WhenGettingComments_ItShouldIssueGetCommentsCommand()
        {
            var expectedResult = new CommentsResult(
                new List <CommentsResult.Item>
            {
                new CommentsResult.Item(CommentId.Random(), PostId.Random(), UserId.Random(), new Username("blah"), new Comment("comment"), DateTime.UtcNow),
            });
            var timestamp = DateTime.UtcNow;

            this.timestampCreator.Setup(v => v.Now()).Returns(timestamp);
            this.requesterContext.Setup(_ => _.GetRequesterAsync()).ReturnsAsync(Requester);
            this.getComments.Setup(v => v.HandleAsync(new GetCommentsQuery(Requester, PostId, timestamp)))
            .Returns(Task.FromResult(expectedResult))
            .Verifiable();

            var result = await this.target.GetComments(PostId.Value.EncodeGuid());

            Assert.AreEqual(expectedResult, result);
            this.getComments.Verify();
        }
Exemplo n.º 8
0
        public async Task <CommentsResult> Get(int take = 10, int skip = 0, string filter = "", string order = "Filter")
        {
            var commentRepository = _unitOfWork.GetRepository <Comment>();
            var items             = new List <CommentItem>();
            var t     = commentRepository.GetAll();
            var query = commentRepository.GetAll().Include(a => a.Posts).Select(c => new CommentItem
            {
                Id           = c.Id,
                ParentId     = c.ParentId,
                PostId       = c.Posts.Id,
                Content      = c.Content,
                IsApproved   = c.IsApproved,
                DisplayName  = c.DisplayName,
                Email        = c.Email,
                DateCreated  = c.CreateDate.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture),
                Ip           = c.Ip,
                RelativeLink = $"/{c.Posts.Id}#id_{c.Id}"
            })
                        .Skip(skip);

            if (take > 0)
            {
                query = query.Take(take);
            }
            var list = await query.ToListAsync();

            foreach (var item in list)
            {
                item.HasChildren = (commentRepository.Count(m => m.ParentId == item.Id) > 0);
            }
            var commentsResult = new CommentsResult();

            commentsResult.Items        = list;
            commentsResult.SelectedItem = new CommentItem();
            commentsResult.Detail       = new CommentItem();
            return(commentsResult);
        }
Exemplo n.º 9
0
 public Task <CommentsResult> GetCommentsAsync(long sinceVersion = EtagVersion.Any)
 {
     return(Task.FromResult(CommentsResult.FromEvents(events, Version, (int)sinceVersion)));
 }