// Example URL: https://fieldscribeapi2017.azurewebsites.net/events/1/entries public IList <Entry> GetEntriesByEventId(int eventId) { try { JObject jsonEntryObj = JObject.Parse( FieldScribeAPIRequests.GETAsync( FieldScribeAPIRequests.FieldScribeAPIRootAddress + "events/" + eventId + "/entries?limit=100")); IList <Entry> entriesList = new List <Entry>(); var tokens = jsonEntryObj["value"].Children(); foreach (JToken token in tokens) { entriesList.Add(token.ToObject <Entry>()); } return(entriesList); } catch (Exception ex) { MessageBox.Show("Failed to get entries by event id!", "Unexpected Error!", MessageBoxButton.OK, MessageBoxImage.Error); throw ex; } }
// Example URL: https://fieldscribeapi2017.azurewebsites.net/entries/1 public Entry GetEntryByEntryId(int entryId) { try { JObject jsonEntryObj = JObject.Parse( FieldScribeAPIRequests.GETAsync( FieldScribeAPIRequests.FieldScribeAPIRootAddress + "entries/" + entryId + "?limit=1")); var entry = new Entry { EntryID = Convert.ToInt32(jsonEntryObj["entryID"].ToString()), EventID = Convert.ToInt32(jsonEntryObj["eventID"].ToString()), AthleteID = Convert.ToInt32(jsonEntryObj["athleteID"].ToString()), CompNum = Convert.ToInt32(jsonEntryObj["compNum"].ToString()), CompetePosition = Convert.ToInt32(jsonEntryObj["competePosition"].ToString()), LastName = jsonEntryObj["lastName"].ToString(), FirstName = jsonEntryObj["firstName"].ToString(), TeamName = jsonEntryObj["teamName"].ToString(), Marks = jsonEntryObj["marks"].ToObject <Mark[]>() }; return(entry); } catch (Exception ex) { MessageBox.Show("Failed to get entry by entry id!", "Unexpected Error!", MessageBoxButton.OK, MessageBoxImage.Error); throw ex; } }
// Example URL: https://fieldscribeapi2017.azurewebsites.net/athletes/99 public Athlete GetAthleteByAthleteId(int athleteId) { try { JObject jsonAthleteObj = JObject.Parse( FieldScribeAPIRequests.GETAsync( FieldScribeAPIRequests.FieldScribeAPIRootAddress + "athletes/" + athleteId + "?limit=1")); var athlete = new Athlete { AthleteId = Convert.ToInt32(jsonAthleteObj["athleteId"].ToString()), MeetId = Convert.ToInt32(jsonAthleteObj["meetId"].ToString()), CompNum = Convert.ToInt32(jsonAthleteObj["compNum"].ToString()), FirstName = jsonAthleteObj["firstName"].ToString(), LastName = jsonAthleteObj["lastName"].ToString(), TeamName = jsonAthleteObj["teamName"].ToString(), Gender = jsonAthleteObj["gender"].ToString() }; return(athlete); } catch (Exception ex) { MessageBox.Show("Failed to get athlete by athlete id!", "Unexpected Error!", MessageBoxButton.OK, MessageBoxImage.Error); throw ex; } }
// TODO: Refactor GetAthletesByMeetId method, very similar code to the GetAllAthletes mehtod above // Example URL: https://fieldscribeapi2017.azurewebsites.net/meets/1/athletes public IList <Athlete> GetAthletesByMeetId(int meetId) { try { IList <JToken> athleteTokens; IList <Athlete> athletes = new List <Athlete>(); JObject jsonAthletesObj = JObject.Parse( FieldScribeAPIRequests.GETAsync( FieldScribeAPIRequests.FieldScribeAPIRootAddress + "meets/" + meetId + "/athletes?limit=1")); // Set the var that holds the total athlete count var totalAthletes = Convert.ToUInt32(jsonAthletesObj["size"].ToString()); // When the meet does not exist expect 0 total athletes if (totalAthletes < 1) { throw new InvalidOperationException(); } // Add the first athlete to the athletes list athletes.Add(jsonAthletesObj["value"].Children().ToList().First().ToObject <Athlete>()); // Can not have an offset of zero, start at one and get all athletes in the database for (int offsetNum = 1; offsetNum < totalAthletes; offsetNum += 100) { jsonAthletesObj = JObject.Parse( FieldScribeAPIRequests.GETAsync( FieldScribeAPIRequests.FieldScribeAPIRootAddress + "meets/" + meetId + "/athletes?limit=100&offset=" + offsetNum)); athleteTokens = jsonAthletesObj["value"].Children().ToList(); // Add current 100 athlete tokens to the athlete list foreach (JToken item in athleteTokens) { athletes.Add(item.ToObject <Athlete>()); } } return(athletes); } catch (Exception ex) { MessageBox.Show("Failed to get athletes by meet id!", "Unexpected Error!", MessageBoxButton.OK, MessageBoxImage.Error); throw ex; } }
public IList <Meet> RetrieveAllMeets() { JObject jsonMeetObj = JObject.Parse(FieldScribeAPIRequests.GETAsync( FieldScribeAPIRequests.FieldScribeAPIRootAddress + "meets?limit=100&orderBy=meetDate%20desc")); IList <JToken> results = jsonMeetObj["value"].Children().ToList(); IList <Meet> meets = new List <Meet>(); foreach (JToken item in results) { meets.Add(item.ToObject <Meet>()); } return(meets); }
public Mark RetrieveMarksByEntryId(int entryId) { JObject jsonMarkObj = JObject.Parse(FieldScribeAPIRequests.GETAsync(FieldScribeAPIRequests.FieldScribeAPIRootAddress + "entries/" + entryId + "/marks?limit=1")); return(jsonMarkObj["value"].Children().ToList().First().ToObject <Mark>()); }