Beispiel #1
0
        /// <summary>
        /// Subscribes to a quiz given the ID
        /// </summary>
        /// <param name="dbId">the ID of the quiz to sub to</param>
        /// <param name="quizzesSearched">the quizzes currently displayed (used to get info about the quiz from the dbid)</param>
        /// <returns>If the subscription was successful</returns>
        public static async Task <OperationReturnMessage> SubscribeToQuizAsync(string dbId, List <QuizInfo> quizzesSearched)
        {
            if (QuizRosterDatabase.GetQuizInfo(dbId) == null) // make sure it isn't in yet
            {
                OperationReturnMessage returnMessage = await Task.Run(async() => await ServerOperations.SubscribeToQuiz(dbId));

                if (returnMessage == OperationReturnMessage.True)
                {
                    QuizInfo quiz             = quizzesSearched.Where(quizInfo => quizInfo.DBId == dbId).First();
                    string   lastModifiedDate = await Task.Run(() => ServerOperations.GetLastModifiedDate(dbId));

                    QuizInfo newInfo = new QuizInfo
                    {
                        DBId             = quiz.DBId,
                        AuthorName       = quiz.AuthorName,
                        QuizName         = quiz.QuizName,
                        Category         = quiz.Category,
                        LastModifiedDate = lastModifiedDate,
                        SyncStatus       = (int)SyncStatusEnum.NotDownloadedAndNeedDownload // 4 to represent not present in local directory and need download
                    };
                    QuizRosterDatabase.SaveQuizInfo(newInfo);
                    return(returnMessage);
                }
                else if (returnMessage == OperationReturnMessage.FalseInvalidCredentials)
                {
                    CredentialManager.IsLoggedIn = false;
                    return(returnMessage);
                }
                else
                {
                    return(returnMessage);
                }
            }
            else
            {
                return(OperationReturnMessage.False);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create a new quizinfo and adds it to the Quiz DB.
        /// A copy is stored in the device quiz roster.
        /// </summary>
        /// <param name="authorName">Author</param>
        /// <param name="quizName">Quiz name</param>
        /// <param name="category">Category</param>
        public void NewQuizInfo(string authorName, string quizName, string category)
        {
            QuizInfo newQuizInfo = new QuizInfo(authorName, quizName, category)
            {
                // Sync status is irrelevant in a Quiz Database's copy of the QuizInfo
                SyncStatus = -1
            };

            this.QuizInfo = newQuizInfo;

            Realm realmDB = Realm.GetInstance(App.realmConfiguration(this.dbPath));

            realmDB.Write(() =>
            {
                realmDB.Add(newQuizInfo);
            });

            QuizInfo rosterCopy = new QuizInfo(newQuizInfo)
            {
                SyncStatus = (int)SyncStatusEnum.NeedUpload // Default to 1, meaning "needs upload" in roster
            };

            QuizRosterDatabase.SaveQuizInfo(rosterCopy);
        }