Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. public sealed partial class VotePage : Page
  2. {
  3. public VotePage()
  4. {
  5. this.InitializeComponent();
  6.  
  7. // This will call the OnLoaded function
  8. this.Loaded += OnLoaded;
  9. }
  10.  
  11. public async void OnLoaded(object sender, RoutedEventArgs e)
  12. {
  13. var response = await start();
  14.  
  15. dynamic dynJson = JsonConvert.DeserializeObject(response);
  16.  
  17. foreach (var item in dynJson)
  18. {
  19. Object votedGame = localSettings.Values[item.slug.ToString()];
  20. string voted = "Collapsed";
  21. string btnVoted = "VOTE";
  22. bool btnEnabled = true;
  23.  
  24. if(votedGame != null)
  25. {
  26. voted = "Visible";
  27. btnVoted = "VOTED!";
  28. btnEnabled = false;
  29. }
  30.  
  31. listofGames.Add(new Games { Title = item.name, Votes = item.votes, Slug = item.slug, Voted = voted, BtnVoted = btnVoted, BtnEnabled = btnEnabled });
  32. }
  33.  
  34. gamesList.ItemsSource = listofGames;
  35. }
  36.  
  37. public class GamesList
  38. {
  39. public List<Game> Games { get; set; }
  40. public String Name { get; set; }
  41.  
  42. public GamesList(String databaseName)
  43. {
  44. Name = databaseName;
  45.  
  46. // This won't work because there is no await.
  47. Games = DataService.GetGames;
  48. }
  49.  
  50. public async Task<List<Game>> GetGames()
  51. {
  52. Debug.WriteLine("GET for games.");
  53.  
  54. var response = await start();
  55.  
  56. dynamic dynJson = JsonConvert.DeserializeObject(response);
  57.  
  58. foreach (var item in dynJson)
  59. {
  60. Object votedGame = localSettings.Values[item.slug.ToString()];
  61. string voted = "Collapsed";
  62. string btnVoted = "VOTE";
  63. bool btnEnabled = true;
  64.  
  65. if (votedGame != null)
  66. {
  67. voted = "Visible";
  68. btnVoted = "VOTED!";
  69. btnEnabled = false;
  70. }
  71.  
  72. listofGames.Add(new Game { Title = item.name, Votes = item.votes, Slug = item.slug, Voted = voted, BtnVoted = btnVoted, BtnEnabled = btnEnabled });
  73. }
  74.  
  75. return new List<Game>();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement