Beispiel #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     object[] parameters = e.Parameter as object[];
     if (parameters != null && parameters[0] != null && parameters[1] != null)
     {
         this.DataContext = _viewModel = new StoryCommentViewModel(parameters[0].ToString(), parameters[1] as StoryExtra);
     }
 }
        public async Task <List <StoryCommentViewModel> > GetStoryCommentsViewModel()
        {
            List <StoryCommentViewModel> storyComments = new List <StoryCommentViewModel>();
            IEnumerable <Story>          stories       = await _storyService.GetStoriesInParallelFixed();

            foreach (Story story in stories)
            {
                StoryCommentViewModel viewModel = new StoryCommentViewModel();
                viewModel.Id   = story.Id;
                viewModel.Url  = story.Url;
                viewModel.Time = story.Time;
                viewModel.Text = string.Empty;
                viewModel.Type = story.Type;

                if (story.Kids.Count > 0)
                {
                    foreach (string commentId in story.Kids)
                    {
                        HttpResponseMessage childResponse = await _client.GetAsync(BaseUrl + "item/" + commentId + ".json?print=pretty").ConfigureAwait(false);

                        string childContent = await childResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        Comment comment = JsonConvert.DeserializeObject <Comment>(childContent);

                        //Overwrite everything but Url for now.
                        //Not a longterm solution just to use for UI.
                        viewModel.Id   = comment.Id;
                        viewModel.Time = comment.Time;
                        viewModel.Type = comment.Type;
                        viewModel.Text = comment.Text;
                        storyComments.Add(viewModel);
                    }
                }
                else
                {
                    storyComments.Add(viewModel);
                }
            }

            return(storyComments);
        }