Beispiel #1
0
        async void OnDeleteButtonClicked(object sender, EventArgs e)
        {
            if (adminAuth.Username != null && adminAuth.Password != null)
            {
                var answer = await DisplayAlert("Delete", "Are you sure you want to delete the option?", "Yes", "No");

                Button deleteButton = (Button)sender;
                string optionID     = deleteButton.StyleId;
                if (answer)
                {
                    //If user confirm to delete the option, send the HTTP request
                    activityIndicator.IsVisible = true;
                    activityIndicator.IsRunning = true;

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostDeleteOption(adminAuth.Username, adminAuth.Password, optionID));

                    string httpResult = httpTask.ToString();

                    activityIndicator.IsVisible = false;
                    activityIndicator.IsRunning = false;

                    if (httpResult == "Poll option successfully deleted!")
                    {
                        await DisplayAlert("Success", "Poll option has been successfully deleted!", "OK");

                        var page     = App.Current.MainPage as rootPage;
                        var pollPage = new pollPage();
                        page.changePage(pollPage);
                    }
                    else
                    {
                        await DisplayAlert("Failed", httpResult, "OK");
                    }
                }
            }
        }