Exemplo n.º 1
0
        public void update(Test test, int subjectId)
        {
            if (DataSetConverter.fromDsToSingle.toInt.convert(
                    SqlLiteSimpleExecute.execute(queryConfigurator.countOfObject(test.Id))) == 0)
            {
                throw new ObjectIsNotExistYet();
            }

            SqlLiteSimpleExecute.execute(queryConfigurator.updateTestsSubject(
                                             test.Id, subjectId));

            SqlLiteSimpleExecute.execute(queryConfigurator.updateTestName(
                                             test.Id, EncryptWorker.getInstance().encrypt(test.Name)));
            int id = test.Id;

            SqlLiteSimpleExecute.execute(queryConfigurator.
                                         updateTestsQuestionsNumber(id, test.QuestionsNumber));

            SqlLiteSimpleExecute.execute(queryConfigurator.
                                         updateTestsRequeredUnswersNumber(id, test.RequeredUnswersNumber));

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