예제 #1
0
        public async Task <List <NewsComments> > ReloadCommentsAsync()
        {
            try
            {
                LoadStatus = LoadMoreStatus.StausLoading;

                var result = await StoreManager.NewsDetailsService.GetCommentAsync(news.Id, pageIndex, pageSize);

                if (result.Success)
                {
                    var newsComments = JsonConvert.DeserializeObject <List <NewsComments> >(result.Message.ToString());
                    if (newsComments.Count > 0)
                    {
                        if (pageIndex == 1)
                        {
                            NewsComments.Clear();
                        }
                        NewsComments.AddRange(newsComments);
                        pageIndex++;
                        if (newsComments.Count < pageSize)
                        {
                            LoadStatus = LoadMoreStatus.StausEnd;
                        }
                        else
                        {
                            LoadStatus = LoadMoreStatus.StausDefault;
                        }
                    }
                    else
                    {
                        LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                    }
                }
                else
                {
                    Crashes.TrackError(new Exception()
                    {
                        Source = result.Message
                    });
                    LoadStatus = LoadMoreStatus.StausError;
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                LoadStatus = LoadMoreStatus.StausError;
            }
            return(NewsComments);
        }
예제 #2
0
        async Task ExecuteCommentCommandAsync()
        {
            var result = await StoreManager.NewsDetailsService.GetCommentAsync(news.Id, pageIndex, pageSize);

            if (result.Success)
            {
                var news = JsonConvert.DeserializeObject <List <NewsComments> >(result.Message.ToString());
                if (news.Count > 0)
                {
                    if (pageIndex == 1 && NewsComments.Count > 0)
                    {
                        NewsComments.Clear();
                    }
                    NewsComments.AddRange(news);
                    pageIndex++;
                    if (NewsComments.Count >= pageSize)
                    {
                        LoadStatus  = LoadMoreStatus.StausDefault;
                        CanLoadMore = true;
                    }
                    else
                    {
                        LoadStatus  = LoadMoreStatus.StausEnd;
                        CanLoadMore = false;
                    }
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Log.SaveLog("NewsDetailsViewModel.GetCommentAsync", new Exception()
                {
                    Source = result.Message
                });
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausError : LoadMoreStatus.StausFail;
            }
        }