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); }
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; }
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"); }
public List<Question> FetchQuestionsNotInTheTestTemplate(TestTemplate template) { return Questions.Where(q => !q.TestTemplates.Contains(template)).ToList(); }
public void AddToTemplate(TestTemplate template) { TestTemplates.Add(template); }
public void RemoveFromTemplate(TestTemplate template) { TestTemplates.Remove(template); }
public bool IsInTestTemplate(TestTemplate template) { return TestTemplates.FirstOrDefault(t => t.Id.Equals(template.Id)) != null ? true : false; }
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(); }
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; } }
private void deleteTestTemplate(TestTemplate template) { template.Questions.Clear(); _context.TestTemplates.Remove(template); }