Exemplo n.º 1
0
        public void CheckQuestions(QuestionList questions)
        {
            foreach (Question question in questions.Questions)
            {
                if (string.IsNullOrEmpty(question.Name))
                {
                    throw new ScoringQuestionNameException();
                }

                if (question.Type == OQuestionType.Collection)
                {
                    foreach (Answer answer in question.Answers)
                    {
                        if (string.IsNullOrEmpty(answer.Name))
                        {
                            throw new ScoringQuestionNameException();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public QuestionList AddQuestion(QuestionList questions)
 {
     using (SqlConnection conn = _manager.GetConnection())
     using (SqlTransaction t = conn.BeginTransaction())
     {
         try
         {
             QuestionList list = new QuestionList();
             foreach (Question question in questions.Questions)
             {
                 list.Questions.Add(_manager.AddQuestion(question, t));
             }
             t.Commit();
             return list;
         }
         catch (Exception)
         {
             if (t != null) t.Rollback();
             throw;
         }
     }
 }
Exemplo n.º 3
0
        public void UpdateQuestionValues(QuestionList questions, int loanId)
        {
            using (SqlConnection conn = _manager.GetConnection())
            using (SqlTransaction t = conn.BeginTransaction())
            {

                try
                {
                    foreach (Question question in questions.Questions)
                    {
                        _manager.UpdateQuestionValues(question, loanId, t);
                    }
                    t.Commit();
                }
                catch (Exception)
                {
                    if (t != null) t.Rollback();
                    throw;
                }
            }
        }
Exemplo n.º 4
0
        public void UpdateQuestions(QuestionList initialList, QuestionList newList)
        {
            using (SqlConnection conn = _manager.GetConnection())
            using (SqlTransaction t = conn.BeginTransaction())
            {
                try
                {
                    // delete outdated questions
                    foreach (Question question in initialList.Questions)
                    {
                        bool notFound = true;
                        foreach (Question question1 in newList.Questions)
                        {
                            if (question == question1)
                                notFound = false;
                        }
                        if (notFound)
                            DeleteQuestion(question);
                    }

                    foreach (Question question in newList.Questions)
                    {
                        if (question.Id > 0)
                        {
                            _manager.UpdateQuestion(question, t);
                        }
                        else
                        {
                            question.Id = _manager.AddQuestion(question, t).Id;
                        }
                    }
                    t.Commit();
                }
                catch (Exception)
                {
                    if (t != null) t.Rollback();
                    throw;
                }
            }
        }