// 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/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; } }
// 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; } }
// Probably can limit return type later, but returning full HttpResponse for now // for more flexiblity. I want to have logic based on the StatusCode within the // HttpResponseMessage. Could handle that here later. public HttpResponseMessage AddMeet(Meet meet) { string jsonMeetObj = JsonConvert.SerializeObject(meet); var response = FieldScribeAPIRequests.POSTJsonWithTokenAsync( jsonMeetObj, "meets", TokenManager.Instance.Token); return(response); }
public HttpResponseMessage DeleteMeet(Meet meet) { int meetId = meet.MeetId; var response = FieldScribeAPIRequests.POSTJsonWithTokenAsync( "", "meets/" + meet.MeetId + "/delete", TokenManager.Instance.Token); return(response); }
public (bool, IList <User>) GetScribesForMeet(int meetId, string token) { HttpResponseMessage response = FieldScribeAPIRequests .GETwithTokenAsync("users/scribes/" + meetId + "?orderBy=lastName", token); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(true, HttpToList(response)); } return(false, null); }
// 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 bool RemoveScribe( int meetId, Guid userId, string token) { HttpResponseMessage response = FieldScribeAPIRequests .POSTJsonWithTokenAsync(JsonConvert.SerializeObject( new AssignScribeForm { UserId = userId, MeetId = meetId }), "users/remove", token); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(true); } return(false); }
public (bool, IList <User>) GetScribes(string[] searchTerms, string token) { string jsonObject = JsonConvert.SerializeObject( new SearchTermsForm { SearchTerms = searchTerms }); HttpResponseMessage response = FieldScribeAPIRequests .POSTJsonWithTokenAsync(jsonObject, "users/scribes?orderBy=lastName", token); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(true, HttpToList(response)); } return(false, null); }
public (bool, User) GetLoggedInUser(string token) { HttpResponseMessage response = FieldScribeAPIRequests.GETwithTokenAsync( "users/me", token); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Task <string> receiveStream = response.Content.ReadAsStringAsync(); User _user = JsonConvert .DeserializeObject <User>(receiveStream.Result); return(true, _user); } return(false, null); }
public (bool, string) RegisterScribe(RegisterForm form, string token) { HttpResponseMessage response = FieldScribeAPIRequests .POSTJsonWithTokenAsync(JsonConvert.SerializeObject( form), "users/scribe", token); if (response.StatusCode == System.Net.HttpStatusCode.Created) { return(true, "Scribe successfully added"); } if (response.StatusCode == System.Net.HttpStatusCode.Conflict) { return(false, "User with email " + form.Email + " already exists"); } return(false, "Registration failed. Try again."); }
public (bool success, string Error) GetToken() { OpenIdConnectRequest request = new OpenIdConnectRequest { GrantType = "password", Username = _creds.Username, Password = _creds.Password }; List <KeyValuePair <string, string> > data = new List <KeyValuePair <string, string> >(); data.Add(new KeyValuePair <string, string>("grant_type", "password")); data.Add(new KeyValuePair <string, string>("username", _creds.Username)); data.Add(new KeyValuePair <string, string>("password", _creds.Password)); FormUrlEncodedContent content = new FormUrlEncodedContent(data); string jsonMeetObj = String.Concat("grant_type=password&username="******"&password="******"token"); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Task <string> receiveStream = response.Content.ReadAsStringAsync(); TokenResponse tokenObject = JsonConvert .DeserializeObject <TokenResponse>(receiveStream.Result); _token = tokenObject.access_token; _expireTime = DateTime.Now.AddSeconds(tokenObject.expires_in); return(true, null); } _token = ""; // Return error message instea of null later if needed return(false, null); }
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>()); }