Skip to content

Commit

Permalink
guillegr123#9 Add functions to get all matches, all stadiums and all …
Browse files Browse the repository at this point in the history
…teams
  • Loading branch information
willescobar30 committed Jun 29, 2018
1 parent f3a4bf0 commit aa93243
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 40 deletions.
5 changes: 4 additions & 1 deletion ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ static void Main(string[] args)
{
Console.WriteLine("Hello World!");

HttpClientMatch.downloadJSONData();
HttpClientMatch.downloadJSONData();
Console.ReadKey();

HttpClientMatch.getAllMatches();
Console.ReadKey();
}
}
Expand Down
106 changes: 79 additions & 27 deletions QW.ExternalApi/HttpClientMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,112 @@ public class HttpClientMatch
{

private static SynchronizationContext synchronizationContext;
public static RootObject worldCupDara;
public static RootObject worldCupDara;

public static async void downloadJSONData()
{

try
{
//PERFORM IN BACKGROUND
// await Task.Run(async () =>
// {
worldCupDara = await "https://raw.githubusercontent.com/lsv/fifa-worldcup-2018/master/data.json".GetJsonAsync<RootObject>();
worldCupDara = await "https://raw.githubusercontent.com/lsv/fifa-worldcup-2018/master/data.json".GetJsonAsync<RootObject>();

//Console.WriteLine(users.ToString());
/* foreach (Team user in worldCupDara.teams)
{
synchronizationContext.Post(new SendOrPostCallback(value =>
{
//UPDATE ComboBox
}), user.Name);
}*/
// });
/* foreach (Team user in worldCupDara.teams)
{
synchronizationContext.Post(new SendOrPostCallback(value =>
{
//UPDATE ComboBox
}), user.Name);
}*/
// });
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}

public Team getTeamByfifaCode(String fifaCode)
//FUNCTION TO GET ALL TEAMS
public static List<Team> getTeams()
{
foreach (Team user in worldCupDara.teams)
List<Team> teams = null;
teams = worldCupDara.teams;
foreach (var item in teams)
{
synchronizationContext.Post(new SendOrPostCallback(value =>
{
//UPDATE ComboBox
//myComboBox.Items.Add(value as string);

}), user.fifaCode);
Console.WriteLine("id: " + item.fifaCode);

}
return teams;
}

//FUNCTION TO GET ALL STADIUMS
public static List<Stadium> getStadiums()
{
List<Stadium> stadiums = null;
stadiums = worldCupDara.stadiums;
foreach (var item in stadiums)
{

Console.WriteLine("id: " + item.name);

return null;
}
return stadiums;
}

public static List<Match10> getGroupMatches()
{
List<Match10> groupMatches = null;
// downloadJSONData();
groupMatches = worldCupDara.groups.a.matches;
groupMatches.AddRange(worldCupDara.groups.b.matches);
groupMatches.AddRange(worldCupDara.groups.c.matches);
groupMatches.AddRange(worldCupDara.groups.d.matches);
groupMatches.AddRange(worldCupDara.groups.e.matches);
groupMatches.AddRange(worldCupDara.groups.f.matches);
groupMatches.AddRange(worldCupDara.groups.g.matches);
groupMatches.AddRange(worldCupDara.groups.h.matches);

return groupMatches;
}


public static List<Match10> getKnockoutMatches()
{
List<Match10> knockoutmatches = null;

knockoutmatches = worldCupDara.knockout.round_16.matches;
knockoutmatches.AddRange(worldCupDara.knockout.round_8.matches);
knockoutmatches.AddRange(worldCupDara.knockout.round_4.matches);
knockoutmatches.AddRange(worldCupDara.knockout.round_2.matches);
knockoutmatches.AddRange(worldCupDara.knockout.round_2_loser.matches);


return knockoutmatches;
}

//FUNCTION TO GET ALL MATCHES
public static List<Match10> getAllMatches()
{

List<Match10> Allmatches = null;
//downloadJSONData();
Allmatches = getGroupMatches();
Allmatches.AddRange(getKnockoutMatches());
Console.WriteLine(Allmatches.Count);
return Allmatches;
}




}

class User
{
public string Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}


}
24 changes: 12 additions & 12 deletions QW.ExternalApi/Models/Matches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class A
public string name { get; set; }
public object winner { get; set; }
public object runnerup { get; set; }
public List<Match> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match2
Expand All @@ -78,7 +78,7 @@ public class B
public string name { get; set; }
public object winner { get; set; }
public object runnerup { get; set; }
public List<Match2> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match3
Expand All @@ -101,7 +101,7 @@ public class C
public string name { get; set; }
public object winner { get; set; }
public object runnerup { get; set; }
public List<Match3> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match4
Expand All @@ -124,7 +124,7 @@ public class D
public string name { get; set; }
public object winner { get; set; }
public object runnerup { get; set; }
public List<Match4> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match5
Expand All @@ -147,7 +147,7 @@ public class E
public string name { get; set; }
public object winner { get; set; }
public object runnerup { get; set; }
public List<Match5> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match6
Expand All @@ -170,7 +170,7 @@ public class F
public string name { get; set; }
public object winner { get; set; }
public object runnerup { get; set; }
public List<Match6> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match7
Expand All @@ -193,7 +193,7 @@ public class G
public string name { get; set; }
public object winner { get; set; }
public object runnerup { get; set; }
public List<Match7> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match8
Expand All @@ -216,7 +216,7 @@ public class H
public string name { get; set; }
public object winner { get; set; }
public object runnerup { get; set; }
public List<Match8> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Groups
Expand Down Expand Up @@ -252,7 +252,7 @@ public class Match9
public class Round16
{
public string name { get; set; }
public List<Match9> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match10
Expand Down Expand Up @@ -300,7 +300,7 @@ public class Match11
public class Round4
{
public string name { get; set; }
public List<Match11> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match12
Expand All @@ -324,7 +324,7 @@ public class Match12
public class Round2Loser
{
public string name { get; set; }
public List<Match12> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Match13
Expand All @@ -348,7 +348,7 @@ public class Match13
public class Round2
{
public string name { get; set; }
public List<Match13> matches { get; set; }
public List<Match10> matches { get; set; }
}

public class Knockout
Expand Down

0 comments on commit aa93243

Please sign in to comment.