private async void UpdateButton_Click(object sender, RoutedEventArgs e) { MyThingObj data = new MyThingObj(); byte[] fileBytes = null; if (file != null) { using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync()) { fileBytes = new byte[stream.Size]; using (DataReader reader = new DataReader(stream)) { await reader.LoadAsync((uint)stream.Size); reader.ReadBytes(fileBytes); } } } else { data.image = existItemList[0].image; } data.rfid = rfid.Text; data.name = itemName.Text; data.image = fileBytes; data.lastUpdatedAt = DateTime.Now; data.createdAt = existItemList[0].createdAt; data.type = type.Text; data.status = "1"; data.location = existItemList[0].location; data.id = int.Parse(id.Text); HttpWebRequest Addrequest = (HttpWebRequest)WebRequest.Create("http://mythingapi.azurewebsites.net/api/MyThings/"+id.Text); Addrequest.Method = "PUT"; Addrequest.ContentType = "application/json;charset=utf-8"; Addrequest.Accept = "application/json;charset=utf-8"; Addrequest.BeginGetRequestStream((ar) => { System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); byte[] bytes = encoding.GetBytes(JsonConvert.SerializeObject(data)); Stream arStream = Addrequest.EndGetRequestStream(ar); arStream.Write(bytes, 0, bytes.Length); Addrequest.BeginGetResponse((arRes) => { HttpWebResponse thingresponse = (HttpWebResponse)Addrequest.EndGetResponse(arRes); }, Addrequest); }, Addrequest); }
public MainPage() { this.InitializeComponent(); DataContext = new MyThingObj(); LoadData(); this.NavigationCacheMode = NavigationCacheMode.Required; PickAFileButton.Click += new RoutedEventHandler(PickAFileButton_Click); button.Click += UpdateButton_Click; }