public void AddAnswerToQuestion(QuestionDTO question, AnswerDTO answer) { var answerFac = new AnswerFacade(); using (var context = new AppDbContext()) { var quest = context.Questions .Include(t => t.ThematicArea).Include(t => t.Answers) .SingleOrDefault(q => q.Id == question.Id); if (quest == null) { return; } context.Entry(quest).Collection(c => c.Answers).Load(); int id = answerFac.CreateAnswer(answer); var option = context.Answers.Find(id); quest.Answers.Add(option); context.Entry(quest).State = EntityState.Modified; context.SaveChanges(); } }
public List <QuestionDTO> GetListOfQuestionsByTheirAnswers(List <int> ids) { var listQ = new List <QuestionDTO>(); var ansFac = new AnswerFacade(); foreach (var quesDto in ids.Select(id => GetQuestionById(ansFac.GetAnswerById(id).Question.Id))) { if (!listQ.Select(s => s.Id).Contains(quesDto.Id)) { listQ.Add(quesDto); } } return(listQ); }