async void OnPublishButtonClicked(object sender, EventArgs e) { bool isErrorPresent = false; string errorMessage = ""; string pollQuestion = ""; //Validate inputs if (pollQuestionInput.Text == "") { isErrorPresent = true; errorMessage = "Please enter poll question. "; } if (selectedOption == "") { isErrorPresent = true; errorMessage = "Please enter number of poll option. "; } //Get option inputs string[] options = new string[optionListLayout.Children.Count()]; int count = 0; //Obtain the option inputs foreach (StackLayout layout in optionListLayout.Children) { foreach (View view in layout.Children) { if (view.GetType() == typeof(Frame)) { if (((Frame)view).Content.GetType() == typeof(Entry)) { Entry entry = (Entry)((Frame)view).Content; options[count] = entry.Text; count++; } } } } if (options.Count() <= 0) { isErrorPresent = true; errorMessage = "Please enter poll option fields. "; } if (!isErrorPresent) { if (adminAuth.Username != null && adminAuth.Password != null) { activityIndicator.IsVisible = true; activityIndicator.IsRunning = true; string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostAddPoll(adminAuth.Username, adminAuth.Password, pollQuestionInput.Text, selectedOption, options)); string httpResult = httpTask.ToString(); activityIndicator.IsVisible = false; activityIndicator.IsRunning = false; if (httpResult == "You have succesfully published a poll!") { await DisplayAlert("Success", "Poll has been successfully published!", "OK"); var page = App.Current.MainPage as rootPage; var pollPage = new pollPage(); page.changePage(pollPage); } else { await DisplayAlert("Failed", httpResult, "OK"); } } else { Console.WriteLine("User is not logged in"); } } else { await DisplayAlert("Failed", errorMessage, "OK"); } }