public async Task <bool> UpdateRequestCampus(string Id, VeLogCampus velogCamp) { try { Uri requestUri = new Uri("http://velogdataentry.azurewebsites.net/api/VelogCampusAPI/" + Id); string json = ""; json = Newtonsoft.Json.JsonConvert.SerializeObject(velogCamp); var objClient = new HttpClient(); HttpResponseMessage responseUpdate = await objClient.PutAsync(requestUri, new StringContent(json, System.Text.Encoding.UTF8, "application/json")); if (responseUpdate.IsSuccessStatusCode) { return(true); } else { return(false); } } catch (Exception exCampusUpdate) { var messageDialog = new MessageDialog("Error: " + exCampusUpdate); await messageDialog.ShowAsync(); return(false); } }
private void campus_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { if (dataGridCampus.SelectedIndex > -1) { VeLogCampus record = (VeLogCampus)dataGridCampus.SelectedItem; //casting the object txtCampusId.Text = record.Id.ToString(); txtCampus.Text = record.Campus; } }
private async void btnUpdateCampus_Click(object sender, RoutedEventArgs e) { if (dataGridCampus.SelectedIndex > -1) { if (txtCampus.Text != "") { if (txtCampus.Text.Length <= 100) { VeLogCampus velogCamp = new VeLogCampus(); velogCamp.Id = Convert.ToInt32(txtCampusId.Text); velogCamp.Campus = txtCampus.Text; objRest = new RESTHandler(); bool status = await objRest.UpdateRequestCampus(txtCampusId.Text, velogCamp); if (status == true) { LoadCampusData(); } else { var messageDialog = new MessageDialog("An error occurred, Campus not updated."); await messageDialog.ShowAsync(); } ClearCampusTextFields(); } else { var messageDialog = new MessageDialog("Check Campus length."); await messageDialog.ShowAsync(); } } else { var messageDialog = new MessageDialog("Enter Campus details."); await messageDialog.ShowAsync(); } } else { var messageDialog = new MessageDialog("No record selected."); await messageDialog.ShowAsync(); } }
// **************************************************************************************************** // Campus CRUD private async void btnAddCampus_Click(object sender, RoutedEventArgs e) { if (dataGridCampus.SelectedIndex == -1) { if (txtCampus.Text != "") { if (txtCampus.Text.Length <= 100) { VeLogCampus velogCamp = new VeLogCampus(); velogCamp.Campus = txtCampus.Text; objRest = new RESTHandler(); bool status = await objRest.AddRequestCampus(velogCamp); if (status == true) { LoadCampusData(); } else { var messageDialog = new MessageDialog("An error occurred, Campus not added."); await messageDialog.ShowAsync(); } ClearCampusTextFields(); } else { var messageDialog = new MessageDialog("Check Campus length."); await messageDialog.ShowAsync(); } } else { var messageDialog = new MessageDialog("Enter Campus details."); await messageDialog.ShowAsync(); } } else { var messageDialog = new MessageDialog("This record already exists."); await messageDialog.ShowAsync(); } }