//public static void EditData<T>(T model, string path) where T : class, new() //{ // Uri url = ApiConnectorHelper.UriConnection(path); // var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); // httpWebRequest.ContentType = "application/json"; // string token = System.Configuration.ConfigurationManager.AppSettings["Token"]; // httpWebRequest.Headers.Add("Token", token); // httpWebRequest.Method = "POST"; // try // { // using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) // { // var serialized = JsonConvert.SerializeObject(model); // streamWriter.Write(serialized); // } // var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); // using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) // { // var output = streamReader.ReadToEnd(); // } // } // catch (Exception ex) // { // MessageBox.Show(ex.ToString()); // } // //return output; //} public static int SaveData <T>(T model, string path) where T : class, new() { int output = 0; Uri url = ApiConnectorHelper.UriConnection(path); var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = "application/json"; string token = System.Configuration.ConfigurationManager.AppSettings["Token"]; httpWebRequest.Headers.Add("Token", token); httpWebRequest.Method = "POST"; try { using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var serialized = JsonConvert.SerializeObject(model); streamWriter.Write(serialized); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { output = int.Parse(streamReader.ReadToEnd()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(output); }
public static List <T> GetSelectedJobData <T>(string jobnumber, string path) where T : class, new() { List <T> items = new List <T>(); Uri url = ApiConnectorHelper.UriConnection(path); var client = new WebClient(); string token = System.Configuration.ConfigurationManager.AppSettings["Token"]; client.Headers["Token"] = token; client.Headers.Add("Content-Type", "application/json"); try { var content = client.DownloadString(url + "/" + jobnumber); if (content != null) { var serializer = new DataContractJsonSerializer(typeof(List <T>)); using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(content))) { items = (List <T>)serializer.ReadObject(ms); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(items); }