Exemplo n.º 1
0
        public void DeleteAnswer(UIAnswer answer)
        {
            var s = DbContext.Answers.FirstOrDefault(x => x.Id == answer.Id);

            if (s != null)
            {
                DbContext.Answers.Remove(s);
                DbContext.SaveChanges();
            }
        }
Exemplo n.º 2
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();
     }
 }