public void DeleteAnswer(UIAnswer answer) { var s = DbContext.Answers.FirstOrDefault(x => x.Id == answer.Id); if (s != null) { DbContext.Answers.Remove(s); DbContext.SaveChanges(); } }
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(); } }