private async Task SubQusition(Model.Qusition qusition) { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var content = new StringContent(JsonConvert.SerializeObject(qusition), Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("http://localhost:60671/api/qusition/AddQusition", content); var res = await response.Content.ReadAsAsync <bool>(); if (res == true) { AcceptButton.IsEnabled = false; } }
/// <summary> /// 提交提问 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Submit_Click(object sender, RoutedEventArgs e) { if (Qusitiondetail.Text == "") { Qusitiondetail.PlaceholderText = "没输入内容"; Qusitiondetail.PlaceholderForeground = new SolidColorBrush(Colors.Red); } else if (QusitionDescribe.Text == "") { QusitionDescribe.PlaceholderForeground = new SolidColorBrush(Colors.Red); QusitionDescribe.PlaceholderText = "没输入内容"; } else if (labels.Count == 0) { await ContentD(); } if (QusitionDescribe.Text != "" && Qusitiondetail.Text != "" && labels.Count >= 1) { Model.Qusition qusition = new Model.Qusition { Askerid = myStruct.id, AskTime = DateTime.Now, UpAskTime = DateTime.Now, QusitionTitle = QusitionDescribe.Text, QusitionContent = Qusitiondetail.Text, Qlabel0 = labels[0].Labelname, }; if (labels.Count == 1) { qusition.Qlabel1 = ""; qusition.QLabel2 = ""; } if (labels.Count == 2) { qusition.Qlabel1 = labels[1].Labelname; qusition.QLabel2 = ""; } if (labels.Count == 3) { qusition.Qlabel1 = labels[1].Labelname; qusition.QLabel2 = labels[2].Labelname; } await SubQusition(qusition); } }