public void Delete(DalQuestion e)
 {
     if (context.Database.Connection.State != ConnectionState.Open)
         context.Database.Connection.Open();
     Questions question = context.Set<Questions>().FirstOrDefault(q => q.id == e.Id);
     context.Set<Questions>().Remove(question);
 }
 public void Create(DalQuestion e)
 {
     if (context.Database.Connection.State != ConnectionState.Open)
         context.Database.Connection.Open();
     Questions question = new Questions()
     {
         id = e.Id,
         QuestionNumberInTest = e.QuestionNumberInTest,
         TestId = e.TestId,
         QuestionStructure = e.QuestionStructure
     };
     context.Set<Questions>().Add(question);
 }
 public bool ExistAnswer(DalQuestion question, DalAnswer answer)
 {
     if (context.Database.Connection.State != ConnectionState.Open)
         context.Database.Connection.Open();
     return context.Set<Answers>()
         .Any(answers => answers.AnswerStructure == answer.AnswerStructure 
         && answers.QuestionId == question.Id);
 }
 public IEnumerable<DalAnswer> GetAllAnswers(DalQuestion question)
 {
     if (context.Database.Connection.State != ConnectionState.Open)
         context.Database.Connection.Open();
     IEnumerable<Answers> ormanswers = context.Set<Answers>().Where(answers => answers.QuestionId == question.Id).AsEnumerable();
     List<DalAnswer> result = new List<DalAnswer>();
     foreach(Answers a in ormanswers)
     {
         result.Add(new DalAnswer()
         {
             AnswerStructure = a.AnswerStructure,
             AnswerValue = a.AnswerValue,
             Id = a.id,
             QuestionId = a.QuestionId
         });
     }
     return result;
 }
 public void Update(DalQuestion entity)
 {
     if (context.Database.Connection.State != ConnectionState.Open)
         context.Database.Connection.Open();
     Questions question = context.Set<Questions>().FirstOrDefault(q => q.id == entity.Id);
     question.QuestionNumberInTest = entity.QuestionNumberInTest;
     question.QuestionStructure = entity.QuestionStructure;
     question.TestId = entity.TestId;
 }