예제 #1
0
        /// <summary>
        /// Unsubscribe from a quiz
        /// </summary>
        /// <param name="dbId">ID to unsub from</param>
        /// <returns>If the unsub was successful</returns>
        public static async Task <OperationReturnMessage> UnsubscribeFromQuizAsync(string dbId)
        {
            QuizInfo info = QuizRosterDatabase.GetQuizInfo(dbId);

            if (info.SyncStatus != (int)SyncStatusEnum.NotDownloadedAndNeedDownload)
            {
                string location = App.UserPath + "/" + info.Category + "/" + info.QuizName + "`" + info.AuthorName;
                if (Directory.Exists(location))
                {
                    Directory.Delete(location, true);
                }
            }

            OperationReturnMessage returnMessage = await Task.Run(async() => await ServerOperations.UnsubscribeToQuizAsync(dbId));

            if (returnMessage == OperationReturnMessage.True)
            {
                QuizRosterDatabase.DeleteQuizInfo(dbId);
                return(returnMessage);
            }
            else if (returnMessage == OperationReturnMessage.FalseInvalidCredentials)
            {
                CredentialManager.IsLoggedIn = false;
                return(returnMessage);
            }
            else
            {
                return(returnMessage);
            }
        }
예제 #2
0
        /// <summary>
        /// When a user wants to unsubscribe from a quiz
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ImageButtonUnsubscribe_Clicked(object sender, EventArgs e)
        {
            if (CredentialManager.IsLoggedIn)
            {
                ImageButton button = (sender as ImageButton);
                string      dbId   = button.StyleId;
                bool        answer = await this.DisplayAlert("Are you sure you want to unsubscribe?", "You will no longer get updates of this quiz", "Yes", "No");

                if (answer)
                {
                    ActivityIndicator indicatorSyncing = (button.Parent as StackLayout).Children[(int)SubscribeUtils.SubscribeType.Syncing] as ActivityIndicator;
                    button.IsVisible           = false;
                    indicatorSyncing.IsVisible = true;
                    indicatorSyncing.IsRunning = true;
                    // get rosterInfo
                    QuizInfo rosterInfo = QuizRosterDatabase.GetQuizInfo(dbId);
                    // tell the roster that the quiz is deleted
                    QuizInfo rosterInfoUpdated = new QuizInfo(rosterInfo)
                    {
                        IsDeletedLocally = true,
                        LastModifiedDate = DateTime.Now.ToString()
                    };
                    QuizRosterDatabase.EditQuizInfo(rosterInfoUpdated);

                    OperationReturnMessage returnMessage = await SubscribeUtils.UnsubscribeFromQuizAsync(dbId);

                    if (returnMessage == OperationReturnMessage.True)
                    {
                        (button.Parent as StackLayout).Children[(int)SubscribeUtils.SubscribeType.Subscribe].IsVisible = true; // add in subscribe button
                        QuizRosterDatabase.DeleteQuizInfo(dbId);
                    }
                    else if (returnMessage == OperationReturnMessage.FalseInvalidCredentials)
                    {
                        button.IsVisible = true;
                        await this.DisplayAlert("Invalid Credentials", "Your current login credentials are invalid. Please log in and try again.", "OK");
                    }
                    else
                    {
                        button.IsVisible = true;
                        await this.DisplayAlert("Unsubscribe Failed", "The unsubscription request could not be completed. Please try again.", "OK");
                    }
                    indicatorSyncing.IsVisible = false;
                    indicatorSyncing.IsRunning = false;
                }
            }
            else
            {
                await this.DisplayAlert("Hold on!", "Before you can subscribe to any quizzes, you have to login.", "Ok");
            }
        }
예제 #3
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();
            }
        }