//answer public int AddAnswer(Answer answer, int idQuestion) { AnswerEntity ae = new AnswerEntity(); ae.Answer = answer.AnswerText; ae.Correct = answer.Correct; ae.Question = data.QuestionEntities.First(x => x.IdQuestion == idQuestion); data.SaveChanges(); return ae.IdAnswer; }
public List<Answer> GetAnswers(int IdQuestion) { List<Answer> res= new List<Answer>(); var answers = data.AnswerEntities.Where(x => x.Question.IdQuestion == IdQuestion); foreach (var answer in answers) { Answer answerTemp = new Answer(); answerTemp.IdAnswer = answer.IdAnswer; answerTemp.AnswerText = answer.Answer; answerTemp.Correct = answer.Correct; res.Add(answerTemp); } return res; }