private async void btnUpdate_Click(object sender, EventArgs e) { string category = comboCategory.Text; string notes = txtNotes.Text; DateTime startDateTime = datePicker_start.Value.Date + timePicker_start.Value.TimeOfDay; DateTime endDateTime = datePicker_end.Value.Date + timePicker_end.Value.TimeOfDay; listBoxDisplay.ClearSelected(); listBoxDisplay.Items.Add("Category: " + category); listBoxDisplay.Items.Add("Start: " + startDateTime.ToString()); listBoxDisplay.Items.Add("Finish: " + endDateTime.ToString()); listBoxDisplay.Items.Add("Notes:"); listBoxDisplay.Items.Add(notes); UserEntry newUserEntry = new UserEntry { Category = category, Notes = notes, StartDate = startDateTime, EndDate = endDateTime }; int.TryParse(txtIndividual.Text, out int id); using (var client = new HttpClient()) { // go get the data client.BaseAddress = new Uri(localHostAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response; //PUT response = await client.PutAsJsonAsync("api/UserEntry/" + id.ToString(), newUserEntry); } txtNotes.Clear(); txtIndividual.Clear(); }
private async void btnGetIndividual_Click(object sender, EventArgs e) { listBoxDisplay.Items.Clear(); int.TryParse(txtIndividual.Text, out int id); using (var client = new HttpClient()) { // go get the data client.BaseAddress = new Uri(localHostAddress); client.DefaultRequestHeaders.Accept.Clear(); // tell it that we want JSON back client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response; response = await client.GetAsync("api/UserEntry/" + id.ToString()); if (response.IsSuccessStatusCode) { try { UserEntry userEntry = await response.Content.ReadAsAsync <UserEntry>(); string tempUserEntry = string.Format("{0}\t{1}\t{2}\t{3}\t{4}", userEntry.Id, userEntry.Category, userEntry.Notes, userEntry.StartDate, userEntry.EndDate); listBoxDisplay.Items.Add(tempUserEntry); } catch { MessageBox.Show("Non existent Id"); } } else { listBoxDisplay.Items.Clear(); listBoxDisplay.Items.Add("No data to return"); } } }