public async static Task <bool> Update(Item item) { using (var client = new HttpClient()) { var values = new Dictionary <string, string> { { "id", item.ID.ToString() }, { "barcode", item.Barcode }, { "imageFileName", item.ImageFilename }, { "name", item.Name }, { "datePurchased", item.DatePurchased.ToString("yyyy-MM-dd") }, { "quantity", item.Quantity.ToString() }, { "value", item.Value.ToString() }, { "location", item.Location }, { "category", item.Category }, { "notes", item.Notes } }; var content = new MyFormUrlEncodedContent(values); var response = await client.PostAsync("http://192.168.1.133/inventory/updateItem.php", content); var responseString = await response.Content.ReadAsStringAsync(); bool b = responseString == "\\1"; return(b); } }
public async static Task <bool> AddItemAsProduct(JObject product) { string dateString = (string)product["datePurchased"]; DateTime datePurchased; if (string.IsNullOrEmpty(dateString)) { datePurchased = new DateTime(1, 1, 1); } else { datePurchased = DateTime.Parse(dateString); if (datePurchased.Year == 1) { datePurchased = DateTime.Today; } } using (var client = new HttpClient()) { var values = new Dictionary <string, string> { { "hid", Core.HouseID.ToString() }, { "barcode", (string)product["barcode"] }, { "imageFileName", null }, { "name", (string)product["name"] }, { "datePurchased", datePurchased.ToString("yyyy-MM-dd") }, { "quantity", (string)product["quantity"] }, { "value", (string)product["value"] }, { "location", (string)product["location"] }, { "category", (string)product["category"] }, { "notes", (string)product["notes"] } }; var content = new MyFormUrlEncodedContent(values); var response = await client.PostAsync("http://192.168.1.133/inventory/addItem.php", content); var responseString = await response.Content.ReadAsStringAsync(); bool b = responseString == "1"; return(b); } }
public async static Task UploadImage(string filename, byte[] imageData) { using (var client = new HttpClient()) { var values = new Dictionary <string, string> { { "filename", filename }, { "imageData", Convert.ToBase64String(imageData) } }; var content = new MyFormUrlEncodedContent(values); var response = await client.PostAsync("http://192.168.1.133/inventory/uploadImage.php", content); var responseString = await response.Content.ReadAsStringAsync(); } }
public async static Task <byte[]> GetImage(string filename) { using (var client = new HttpClient()) { var values = new Dictionary <string, string> { { "filename", filename } }; var content = new MyFormUrlEncodedContent(values); var response = await client.PostAsync("http://192.168.1.133/inventory/getImage.php", content); var bytes = await response.Content.ReadAsByteArrayAsync(); return(bytes); } }
public async static Task <bool> DeleteItem(int id) { using (var client = new HttpClient()) { var values = new Dictionary <string, string> { { "id", id.ToString() } }; var content = new MyFormUrlEncodedContent(values); var response = await client.PostAsync("http://192.168.1.133/inventory/deleteItem.php", content); var responseString = await response.Content.ReadAsStringAsync(); bool b = responseString == "1"; return(b); } }
private static byte[] GetContentByteArray(IEnumerable <KeyValuePair <string, string> > nameValueCollection) { if (nameValueCollection == null) { throw new ArgumentNullException("nameValueCollection"); } StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair <string, string> current in nameValueCollection) { if (stringBuilder.Length > 0) { stringBuilder.Append('&'); } stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Key)); stringBuilder.Append('='); stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Value)); } return(Encoding.Default.GetBytes(stringBuilder.ToString())); }
public MyFormUrlEncodedContent(IEnumerable <KeyValuePair <string, string> > nameValueCollection) : base(MyFormUrlEncodedContent.GetContentByteArray(nameValueCollection)) { base.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); }