Exemplo n.º 1
0
        public CommentListData()
        {
            this.CommentList = new List<Comment>();

            for (var i = 0; i < 10; i++)
            {
                var comment = new Comment
                {
                    Author = new User
                    {
                        Name = "澈目",
                        Avatar = "http://img3.douban.com/icon/u80138337-11.jpg",
                        LargeAvatar = "http://img3.douban.com/icon/up80138337-11.jpg"
                    },
                    Text = "留学中介好像就一二线城市城市都多点,其他城市就业也比较少,有同学做了一年也出来了",
                    Time = DateTime.Now.AddMinutes(-20),
                    QuoteComment = new Comment
                    {
                        Text = "倒数第二张,还没有开的时候真的很像双色冰淇淋",
                        Author = new User
                        {
                            Name = "梅子是六月成熟"
                        }
                    }
                };
                
                this.CommentList.Add(comment);
            }
        }
        private async void VoteComment(Comment parameter)
        {
            if (!parameter.CanVote)
            {
                return;
            }

            if (!await this.RequireLogin())
            {
                return;
            }

            var result = await this.RunTaskAsync(this.ApiClient.VoteComment(this.TopicID, parameter.ID));

            if (result != null)
            {
                parameter.CanVote = false;

                if (result.Result)
                {
                    parameter.VoteCount = result.VoteCount;
                }
                else
                {
                    this.ShowToast("您已经投过票了");
                }
            }
        }
        private async void AddComment(Comment parameter)
        {
            if (this.Topic == null || !this.CurrentUser.IsGroupMember(this.Topic.Group.ID))
            {
                await this.Alert("只有小组成员才能发表评论");
                return;
            }

            var vm = new AddCommentPageViewModel(this.Topic, parameter);
            var comment = await vm.Show();

            if (comment != null)
            {
                this.CommentList.LastOrDefault()?.CommentList.Add(comment);
            }
        }