public string putStatus(string eventIDforCheck, bool checkedOrNot) { int checkNoOfPuts = 0; while (1 == 1) { checkNoOfPuts++; if (checkNoOfPuts > 15) { return("Failed"); } try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://dev.dragonflyathletics.com:1337/api/dfkey/events/" + eventIDforCheck + "/status/" + UserName); request.Method = "PUT"; string authheader = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(UserName + ":" + Password)); request.Headers.Add("Authorization", AuthTyoe.ToString() + " " + authheader); PutRootObject pro = new PutRootObject(); pro.Coming = checkedOrNot; var postD = JsonConvert.SerializeObject(pro); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] byte1 = encoding.GetBytes(postD); // Set the content type of the data being posted. request.ContentType = "application/json"; // Set the content length of the string being posted. request.ContentLength = byte1.Length; using (var newStream = new StreamWriter(request.GetRequestStream())) { newStream.Write(postD); } bool test = getCheckBoxStatus(eventIDforCheck); if (checkedOrNot == test) { return("Success"); } throw new ApplicationException("Put was not successful"); } catch (ApplicationException ar) { Console.WriteLine(ar.Message); } catch (Exception) { Console.WriteLine("Error getting images"); //vague handling } } return("Failed"); }
public bool getCheckBoxStatus(string eventIDforCheckStatus) { string strResponseValue = string.Empty; int checkNoOfGet = 0; while (1 == 1) { checkNoOfGet++; if (checkNoOfGet > 10) { return(false); //assuming every event has true or false for coming, otherwise it returns as false default. } try { HttpWebResponse response = httpResponse("http://dev.dragonflyathletics.com:1337/api/dfkey/events/" + eventIDforCheckStatus + "/status/" + UserName); if (response == null) { throw new ApplicationException("Response was null"); } else { using (Stream responseStream = response.GetResponseStream()) { if (responseStream != null) { using (StreamReader reader = new StreamReader(responseStream)) { strResponseValue = reader.ReadToEnd(); PutRootObject robb = JsonConvert.DeserializeObject <PutRootObject>(strResponseValue); return(robb.Coming); // return strResponseValue; } } } } } catch (ApplicationException ar) { Console.WriteLine(ar.Message); } catch (Exception) { Console.WriteLine("Error with the stream"); //vague handling } } }