private void Send_message(object sender, RoutedEventArgs e) { var syncClient = new HttpClient(); //allow api connection //variables that need to be uploaded to the database string email = E_mail.Text; try { var eduselect = Opleiding.Items[Opleiding.SelectedIndex] as ComboBoxItem; string education = eduselect.Content.ToString(); string name = Naam.Text; string question = Vraag.Text; string qid = "http://www.wschaijk.nl/api/api.php/SELECT-question_id-FROM-questions-ORDER-BY-question_id-DESC-LIMIT-1;"; //query for current highest question id var qidCall = syncClient.GetStringAsync(qid); var qidResult = qidCall.Result; //result for the query var gimmeResult = new PrepareForScreenQueryHandler(); var tempid = gimmeResult.ResultOnly(qidResult); //remove unnecessary string elements from result int id = Int32.Parse(tempid); //go from string result to int result id = id + 1; //increment current highest id by one because youre adding a new question string qupload = TextToURL.text_to_string(string.Format("http://www.wschaijk.nl/api/api.php/INSERT-INTO-questions-VALUES({0},-\'{1}\',-\'{2}\',-\'{3}\',-\'{4}\');", id, education, email, name, question)); //upload the question var uploadstuff = syncClient.GetAsync(qupload); string tempanswer = TextToURL.text_to_string(string.Format("http://www.wschaijk.nl/api/api.php/INSERT-INTO-answer-VALUES({0},-\'{1}\',-\'place\',-\'This-question-is-not-yet-answered.\');", id, education)); //upload a dummy answer var uploadta = syncClient.GetAsync(tempanswer); this.Frame.Navigate(typeof(Jaar_1_Project_4.QuestionSystem.mainQpage)); //send user back to main question page } catch (System.ArgumentOutOfRangeException) { this.Frame.Navigate(typeof(Questions)); } }
private void Send_message(object sender, RoutedEventArgs e) { var syncClient = new HttpClient(); //allow internet acces for api interaction int question_id = Int32.Parse(QuestionExtender.CurrentSelectedQuestionID); //id of the question that is currently being answered string who_to_mail = string.Format("http://www.wschaijk.nl/api/api.php/SELECT-email-FROM-questions-WHERE-question_id-=-{0};", question_id); //email adress to notify the person who asked the question string person_name = string.Format("http://www.wschaijk.nl/api/api.php/SELECT-name-FROM-questions-WHERE-question_id-=-{0};", question_id); //name of the person who asked the question var emailCall = syncClient.GetStringAsync(who_to_mail); var emailResult = emailCall.Result; //executes query var nameCall = syncClient.GetStringAsync(person_name); var nameResult = nameCall.Result; //executes query var gimmeResult = new PrepareForScreenQueryHandler(); var email = gimmeResult.ResultOnly(emailResult); //removes unnecessary string elements from the result var name = gimmeResult.ResultOnly(nameResult); //removes unnecessary dtring elements from the result string updatequery = TextToURL.text_to_string(string.Format("http://www.wschaijk.nl/api/api.php/UPDATE-answer-SET-teacher_id-=-\'{0}\',-answer-=-\'{1}\'-WHERE-question_id-=-{2};", DatabaseLoginCheck.LoggedInTeacherName, answerBox.Text, question_id)); var updateanswer = syncClient.GetAsync(updatequery); //upload answer to database string notification = TextToURL.text_to_string(string.Format("http://www.wschaijk.nl/api/api.php/MAIL={0}=Your-question-has-been-answered!=Dear-{1},-your-question-regarding-the-open-day-has-been-answered.-Check-the-Q-and-A-page-for-the-answer.", email, name)); var sendmail = syncClient.GetAsync(notification); //notify the person who asked the question via email this.Frame.Navigate(typeof(Jaar_1_Project_4.QuestionSystem.mainQpage)); //sends user back to the main question page }