public bool Update([FromBody] QuestionDTO questionDTO) { List <Answer> updatedAnswers = new List <Answer>(); foreach (AnswerDTO answerDTO in questionDTO.Answers) { updatedAnswers.Add(new Answer { Id = Guid.NewGuid(), QuestionId = questionDTO.Id, Content = answerDTO.Content, IsCorrect = answerDTO.IsCorrect }); } Question updatedQuestion = questionRepository.GetById(questionDTO.Id); updatedQuestion.Content = questionDTO.Content; updatedQuestion.Difficulty = questionDTO.Difficulty; return(answerRepository.Update(updatedAnswers) && questionRepository.Update(updatedQuestion)); }
public bool Create([FromBody] QuestionDTO questionDTO) { Question newQuestion = new Question { Id = Guid.NewGuid(), BankId = questionDTO.Id, Difficulty = questionDTO.Difficulty, Type = questionDTO.Type, Content = questionDTO.Content }; List <Answer> newAnswers = new List <Answer>(); foreach (AnswerDTO answerDTO in questionDTO.Answers) { newAnswers.Add(new Answer { Id = Guid.NewGuid(), QuestionId = newQuestion.Id, Content = answerDTO.Content, IsCorrect = answerDTO.IsCorrect }); } return(questionRepository.Create(newQuestion) && answerRepository.Create(newAnswers)); }