예제 #1
0
        public void AddTemplateQuestion(TestTemplate template, Guid questionId)
        {
            var question = FetchQuestion(questionId);

            if (question.IsInTestTemplate(template))
                throw new BusinessRuleException("Question already exists in the test template");
            else if (!question.Isvalid)
                throw new BusinessRuleException("Question does not contain either at least 2 choices or 1 choice with answer");
            else
                question.AddToTemplate(template);
        }
예제 #2
0
 public TestInstance UpdateTestInstance(Guid instanceId, TestTemplate newTestTemplate, bool isPractice, int timeLimit)
 {
     var result = FetchTestInstance(instanceId);
     if (!result.IsOpen)
     {
         throw new BusinessRuleException("Unable to update once Test Instance is Open.");
     }
     result.TestTemplate = newTestTemplate;
     result.IsPractice = isPractice;
     result.TimeLimit = timeLimit;
     return result;
 }
예제 #3
0
        public void RemoveTemplateQuestion(TestTemplate template, Guid questionId)
        {
            var question = FetchQuestion(questionId);

            if (question.IsInTestTemplate(template))
                question.RemoveFromTemplate(template);
            else
                throw new RecordNotFoundException("Question does not exists in the template");
        }
예제 #4
0
 public List<Question> FetchQuestionsNotInTheTestTemplate(TestTemplate template)
 {
     return Questions.Where(q => !q.TestTemplates.Contains(template)).ToList();
 }
예제 #5
0
 public void AddToTemplate(TestTemplate template)
 {
     TestTemplates.Add(template);
 }
예제 #6
0
 public void RemoveFromTemplate(TestTemplate template)
 {
     TestTemplates.Remove(template);
 }
예제 #7
0
 public bool IsInTestTemplate(TestTemplate template)
 {
     return TestTemplates.FirstOrDefault(t => t.Id.Equals(template.Id)) != null ? true : false;
 }
예제 #8
0
 public void DeleteTestTemplate(Action action, TestTemplate template)
 {
     if (template.IsBeingUsedInTestInstance)
         throw new BusinessRuleException("Unable to update Test Template because it is being used in a Test Instance");
     action();
 }
예제 #9
0
 public TestTemplate CreateTestTemplate(string name)
 {
     try
     {
         return FetchTestTemplate(name);
         throw new BusinessRuleException("Test Template name already exists");
     }
     catch (RecordNotFoundException)
     {
         var template = new TestTemplate(name);
         TestTemplates.Add(template);
         return template;
     }
 }
예제 #10
0
 private void deleteTestTemplate(TestTemplate template)
 {
     template.Questions.Clear();
     _context.TestTemplates.Remove(template);
 }