Пример #1
0
        private IntHierarchy getTestIndex(int testId)
        {
            for (int i = 0; i < tests.Count; i++)
            {
                if (tests.ElementAt(i).Id == testId)
                {
                    IntHierarchy hi = new IntHierarchy(new Test().GetType());
                    hi.value = i;
                    return(hi);
                }
            }

            throw new GoTestObjectNotFound();
        }
Пример #2
0
        private IntHierarchy getQuestionIndex(int questionId)
        {
            for (int i = 0; i < questions.Count; i++)
            {
                if (questions.ElementAt(i).Id == questionId)
                {
                    IntHierarchy hi = new IntHierarchy(new Question().GetType());
                    hi.value = i;
                    return(hi);
                }
            }

            throw new GoTestObjectNotFound();
        }
Пример #3
0
        public void deleteQuestion(int id)
        {
            IntHierarchy hi = searcher.getQuestionPosition(store, id);

            if (!hi.getLastListType().Equals(new Question().GetType()))
            {
                throw new GoTestObjectNotFound();
            }
            else
            {
                store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
                Questions.ElementAt(hi.getChild().getChild().value).IsDeleted = true;
                notifyObservers();
            }
        }
Пример #4
0
        public void update(int id, Unswer newVersion)
        {
            IntHierarchy hi            = searcher.getQuestionPosition(store, id);
            int          questionIndex = -1;
            int          unswerIndex   = -1;

            if (!hi.getLastListType().Equals(new Unswer().GetType()))
            {
                throw new GoTestObjectNotFound();
            }
            else
            {
                questionIndex = hi.getChild().getChild().value;
                unswerIndex   = hi.getChild().getChild().getChild().value;
            }

            int      rightUnswersCount = 1;
            Question question          = store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
                                         Questions.ElementAt(questionIndex);

            for (int i = 0; i < question.Unswers.Count; i++)
            {
                if (question.Unswers.ElementAt(i).IsRight)
                {
                    rightUnswersCount++;
                }
            }
            if (rightUnswersCount > 1)
            {
                question.QuestionsType = QuestionTypes.multiplyAnswer;
            }
            else
            {
                question.QuestionsType = QuestionTypes.singleAnswer;
            }
            newVersion.Id = store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
                            Questions.ElementAt(questionIndex).Unswers.ElementAt(unswerIndex).Id;
            store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
            Questions.ElementAt(questionIndex).Unswers.
            RemoveAt(unswerIndex);
            store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
            Questions.ElementAt(questionIndex).Unswers.
            Insert(unswerIndex, newVersion);


            notifyObservers();
        }
Пример #5
0
        private IntHierarchy getChildIndex(int id)
        {
            for (int i = 0; i < tests.Count; i++)
            {
                try
                {
                    IntHierarchy hi = new IntHierarchy(new Test().GetType(),
                                                       tests.ElementAt(i).searchObjectIndex(id));
                    hi.value = i;
                    return(hi);
                }
                catch (GoTestObjectNotFound ex)
                {
                }
            }

            throw new GoTestObjectNotFound();
        }
Пример #6
0
        private IntHierarchy getChildIndex(int id)
        {
            for (int i = 0; i < questions.Count; i++)
            {
                try
                {
                    IntHierarchy hi = new IntHierarchy(new Unswer().GetType());
                    hi.value = questions.ElementAt(i).getUnswerIndex(id);
                    IntHierarchy hi2 = new IntHierarchy(new Question().GetType(), hi);
                    hi2.value = i;
                    return(hi2);
                }
                catch (GoTestObjectNotFound ex)
                {
                }
            }

            throw new GoTestObjectNotFound();
        }
Пример #7
0
        public void update(int id, Question newVersion)
        {
            int          questionIndex = -1;
            IntHierarchy hi            = searcher.getQuestionPosition(store, id);

            if (!hi.getLastListType().Equals(new Question().GetType()))
            {
                throw new GoTestObjectNotFound();
            }
            else
            {
                questionIndex = hi.getChild().getChild().value;
            }
            newVersion.Id = store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
                            Questions.ElementAt(questionIndex).Id;
            store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
            Questions.RemoveAt(questionIndex);
            store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
            Questions.Insert(questionIndex, newVersion);
            notifyObservers();
        }
Пример #8
0
 public void update(int id, Test test)
 {
     try
     {
         IntHierarchy hi = searcher.getTestPosition(store, id);
         if (!hi.getLastListType().Equals(new Test().GetType()))
         {
             throw new GoTestObjectNotFound();
         }
         else
         {
             test.Id = store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).Id;
             store.ElementAt(hi.value).Tests.RemoveAt(hi.getChild().value);
             store.ElementAt(hi.value).Tests.Insert(hi.getChild().value, test);
             notifyObservers();
         }
     }
     catch (Exception ex)
     {
         ExceptionHandler.getInstance().processing(ex);
     }
 }