Exemple #1
0
        /// <summary>
        /// 加载评论
        /// </summary>
        /// <returns></returns>
        private async Task LoadComments()
        {
            CommentList commentList;

            if (this.ViewAuthor)
            {
                commentList = await this.RunTaskAsync(this.ApiClient.GetOpCommentList(this.TopicID, 0, PageSize));
            }
            else
            {
                commentList = await this.RunTaskAsync(this.ApiClient.GetCommentList(this.TopicID, 0, PageSize));
            }

            if (commentList == null)
            {
                return;
            }

            var totalPage = commentList.Total / PageSize;

            if (commentList.Total % PageSize > 0)
            {
                totalPage++;
            }

            if (totalPage == 0)
            {
                totalPage = 1;
            }

            this.TotalPage = totalPage;

            if (this.TotalPage > this.CommentList.Count)
            {
                for (var i = this.CommentList.Count; i < this.TotalPage; i++)
                {
                    var item = new CommentListViewModel(this.TopicID, i + 1, this.PageSize, this.ViewAuthor);

                    if (i == 0)
                    {
                        item.Topic = this;
                    }

                    this.CommentList.Add(item);
                }
            }

            this.CurrentComment = this.CommentList.FirstOrDefault();

            if (this.PopularCommentList.Count == 0)
            {
                foreach (var comment in commentList.PopularComments)
                {
                    this.PopularCommentList.Add(comment);
                }
            }

            this.OnPropertyChanged(() => this.HasPopularComments);
        }
        /// <summary>
        /// 加载评论
        /// </summary>
        /// <returns></returns>
        private async Task LoadComments()
        {
            CommentList commentList;

            if (this.ViewAuthor)
            {
                commentList = await this.RunTaskAsync(this.ApiClient.GetOpCommentList(this.TopicID, 0, PageSize));
            }
            else
            {
                commentList = await this.RunTaskAsync(this.ApiClient.GetCommentList(this.TopicID, 0, PageSize));
            }

            if (commentList == null)
            {
                return;
            }

            var totalPage = commentList.Total / PageSize;
            if (commentList.Total % PageSize > 0)
            {
                totalPage++;
            }

            if (totalPage == 0)
            {
                totalPage = 1;
            }

            this.TotalPage = totalPage;

            if (this.TotalPage > this.CommentList.Count)
            {
                for (var i = this.CommentList.Count; i < this.TotalPage; i++)
                {
                    var item = new CommentListViewModel(this.TopicID, i + 1, this.PageSize, this.ViewAuthor);

                    if (i == 0)
                    {
                        item.Topic = this;
                    }

                    this.CommentList.Add(item);
                }
            }

            this.CurrentComment = this.CommentList.FirstOrDefault();

            if (this.PopularCommentList.Count == 0)
            {
                foreach (var comment in commentList.PopularComments)
                {
                    this.PopularCommentList.Add(comment);
                }
            }

            this.OnPropertyChanged(() => this.HasPopularComments);
        }