Beispiel #1
0
        /// <summary>
        /// Called when the user tries to upload a quiz
        /// </summary>
        /// <param name="sender">  </param>
        /// <param name="e">       </param>
        private async void SyncUpload_Clicked(object sender, EventArgs e)
        {
            ImageButton       button           = (sender as ImageButton);
            ActivityIndicator indicatorSyncing = (button.Parent as StackLayout).Children[(int)UISyncStatus.Syncing] as ActivityIndicator;
            string            quizPath         = "/" + button.StyleId + "/" + button.ClassId;

            button.IsVisible           = false;
            indicatorSyncing.IsVisible = true;
            indicatorSyncing.IsRunning = true;
            if (await Task.Run(async() => await ServerOperations.SendQuiz(quizPath)))
            {
                ImageButton buttonSyncNoChange = (button.Parent as StackLayout).Children[(int)UISyncStatus.NoChange] as ImageButton;
                indicatorSyncing.IsVisible   = false;
                buttonSyncNoChange.IsVisible = true;
            }
            else // if it failed to upload
            {
                indicatorSyncing.IsVisible = false;
                button.IsVisible           = true;
                await this.DisplayAlert("Quiz Upload Failed",
                                        "This quiz could not be uploaded to the server. Please try again.",
                                        "OK");
            }
            indicatorSyncing.IsRunning = false;
            this.QuizNumber.Text       =
                "You have published a total of " +
                await Task.Run(() => ServerOperations.GetNumberOfQuizzesByAuthorName(CredentialManager.Username)) +
                " quizzes!";
        }
Beispiel #2
0
        /// <summary>
        /// Deletes the quiz from the roster
        /// </summary>
        private async Task ButtonDelete_Clicked(string DBId)
        {
            bool answer = await this.DisplayAlert("Are you sure you want to delete this quiz?", "This will delete the copy on your device and in the cloud. This is not reversable.", "Yes", "No");

            if (answer)
            {
                // Acquire QuizInfo from roster
                QuizInfo rosterInfo = QuizRosterDatabase.GetQuizInfo(DBId);

                string path = rosterInfo.RelativePath;

                if (rosterInfo != null)
                {
                    string dbId = rosterInfo.DBId;

                    // tell the roster that the quiz is deleted
                    QuizInfo rosterInfoUpdated = new QuizInfo(rosterInfo)
                    {
                        IsDeletedLocally = true,
                        LastModifiedDate = DateTime.Now.ToString()
                    };
                    QuizRosterDatabase.EditQuizInfo(rosterInfoUpdated);

                    // If connected, tell server to delete this quiz If not, it will tell server to delete next time it is connected in QuizRosterDatabase.UpdateLocalDatabase()
                    OperationReturnMessage returnMessage = await ServerOperations.DeleteQuiz(dbId);

                    if (returnMessage == OperationReturnMessage.True)
                    {
                        QuizRosterDatabase.DeleteQuizInfo(dbId);
                    }

                    if (System.IO.Directory.Exists(path))
                    {
                        Directory.Delete(path, true);
                    }

                    this.QuizNumber.Text =
                        "You have published a total of " +
                        await Task.Run(() => ServerOperations.GetNumberOfQuizzesByAuthorName(CredentialManager.Username)) +
                        " quizzes!";
                }
                else
                {
                    await DisplayAlert("Could not delete quiz", "This quiz could not be deleted at this time. Please try again later", "OK");
                }

                // Setup Page again after deletion
                await this.UpdateProfilePageAsync();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Loads the profile content if the user is logged in.
        /// </summary>
        /// <returns> </returns>
        private async Task UpdateProfileContentAsync(string category)
        {
            if (!this.IsContentLoading)
            {
                this.IsContentLoading         = true;
                this.QuizNumber.IsVisible     = true;
                this.PickerCategory.IsVisible = false;
                this.PickerCategory.IsEnabled = false;
                this.StackLayoutQuizStack.Children.Clear();
                this.StackLayoutQuizStack.IsEnabled = false;
                this.ActivityIndicator.IsVisible    = true;
                this.ActivityIndicator.IsRunning    = true;

                await Task.Run(async() =>
                {
                    await this.SetupQuizzes(category);
                    int createdCountFromServer = ServerOperations.GetNumberOfQuizzesByAuthorName(CredentialManager.Username);
                    string frameMessage        = "";
                    if (createdCountFromServer >= 0) // Returns -1 if can't connect to server
                    {
                        if (createdCountFromServer == 0 &&
                            !QuizRosterDatabase.GetRoster()
                            .Any(quizInfo => quizInfo.AuthorName == CredentialManager.Username))
                        {
                            frameMessage = "You haven't made any quizzes yet!";
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                this.PickerCategory.IsVisible = false;
                                this.QuizNumber.IsVisible     = false;
                            });
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                this.QuizNumber.Text          = "You have published a total of " + createdCountFromServer + " quizzes!";
                                this.PickerCategory.IsVisible = true;
                                this.PickerCategory.IsEnabled = true;
                            });
                        }
                    }
                    else
                    {
                        frameMessage = "Could not connect to BizQuiz servers. Please try again later.";
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            this.PickerCategory.IsVisible = true;
                            this.PickerCategory.IsEnabled = true;
                        });
                    }

                    if (frameMessage != "")
                    {
                        Frame frame = new Frame()
                        {
                            CornerRadius      = 10,
                            HorizontalOptions = LayoutOptions.CenterAndExpand,
                            Content           = new Label
                            {
                                Text = frameMessage,
                                HorizontalTextAlignment = TextAlignment.Center,
                                FontSize = 38
                            }
                        };

                        Device.BeginInvokeOnMainThread(() =>
                                                       this.StackLayoutQuizStack.Children.Add(frame));
                    }
                });

                if (this.ToolbarItems.Count <= 0)
                {
                    ToolbarItem accountSettingsButton = new ToolbarItem();
                    accountSettingsButton.Clicked += this.ToolbarItemAccountSettings_Clicked;
                    accountSettingsButton.Icon     = ImageSource.FromFile("ic_settings_white_48dp.png") as FileImageSource;
                    this.ToolbarItems.Add(accountSettingsButton);
                }

                this.IsOnLoginPage = false;
                this.ActivityIndicator.IsRunning    = false;
                this.ActivityIndicator.IsVisible    = false;
                this.StackLayoutQuizStack.IsEnabled = true;
                this.IsContentLoading = false;
            }
        }