Ejemplo n.º 1
0
        public void DeleteQuestion(UIQuestion question)
        {
            var s = DbContext.Questions.FirstOrDefault(x => x.Id == question.Id);

            if (s != null)
            {
                DbContext.Questions.Remove(s);
                DbContext.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 public List <UIAnswer> GetAnswers(UIQuestion question)
 {
     if (question != null)
     {
         var s = DbContext.Questions.FirstOrDefault(x => x.Id == question.Id);
         if (s.Answers != null)
         {
             return(s.Answers.Select(x => new UIAnswer(x.AnswerText, x.IsCorrect, x.Id)).ToList());
         }
     }
     return(new List <UIAnswer>());
 }
Ejemplo n.º 3
0
 public void SaveQuestion(UIQuestion question, UITest test)
 {
     if (question.Id < 0)
     {
         var t = DbContext.Tests.Include("Questions").FirstOrDefault(x => x.Id == test.id);
         if (t != null)
         {
             var quest = new Question(question.QuestionText);
             t.Questions.Add(quest);
             DbContext.SaveChanges();
         }
     }
     else
     {
         var s = DbContext.Questions.FirstOrDefault(x => x.Id == question.Id);
         s.QuestionText = question.QuestionText;
         DbContext.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public void SaveAnswer(UIAnswer answer, UIQuestion question)
 {
     if (answer.Id < 0)
     {
         var t = DbContext.Questions.FirstOrDefault(x => x.Id == question.Id);
         if (t != null)
         {
             var ans = new Answer(answer.AnswerText, answer.IsCorrect);
             t.Answers.Add(ans);
             DbContext.SaveChanges();
         }
     }
     else
     {
         var s = DbContext.Answers.FirstOrDefault(x => x.Id == answer.Id);
         s.AnswerText = answer.AnswerText;
         s.IsCorrect  = answer.IsCorrect;
         DbContext.SaveChanges();
     }
 }