Пример #1
0
        public void update(Question question)
        {
            if (DataSetConverter.fromDsToSingle.toInt.convert(
                    SqlLiteSimpleExecute.execute(queryConfigurator.countOfObject(question.Id))) == 0)
            {
                throw new ObjectIsNotExistYet();
            }
            SqlLiteSimpleExecute.execute(queryConfigurator.updateQuestionContent(question.Id,
                                                                                 EncryptWorker.getInstance().encrypt(question.QuestionsContent)));


            int rightUnswersCount = 0;

            for (int i = 0; i < question.Unswers.Count; i++)
            {
                if (question.Unswers.ElementAt(i).IsRight)
                {
                    rightUnswersCount++;
                }
            }
            if ((question.QuestionsType.getType().Equals(QuestionTypes.singleAnswer)) &
                (rightUnswersCount == 0 | rightUnswersCount > 1))
            {
                throw new QuestionTypeException();
            }
            if (question.QuestionsType.getType().Equals(QuestionTypes.multiplyAnswer) &
                rightUnswersCount < 2)
            {
                throw new QuestionTypeException();
            }

            if (question.QuestionsType.getType().Equals(DbObjects.multiplyAnswer.getName()))
            {
                SqlLiteSimpleExecute.execute(queryConfigurator.updateQuestionType(question.Id,
                                                                                  DbObjects.multiplyAnswer));
            }
            else
            {
                SqlLiteSimpleExecute.execute(queryConfigurator.updateQuestionType(question.Id,
                                                                                  DbObjects.singleAnswer));
            }

            for (int i = 0; i < question.Unswers.Count; i++)
            {
                try
                {
                    if (question.Unswers.ElementAt(i).IsDeleted)
                    {
                        question.Unswers.ElementAt(i).delete();
                    }
                    else
                    {
                        unswerManipalator.update(question.Unswers.ElementAt(i));
                    }
                }
                catch (ObjectIsNotExistYet ex)
                {
                    unswerManipalator.create(question.Unswers.ElementAt(i), question.Id);
                }
            }
        }