update question

This commit is contained in:
Вячеслав 2025-05-13 19:19:43 +05:00
parent 9555497d4e
commit 7cbff22d8a
3 changed files with 45 additions and 0 deletions

View file

@ -60,6 +60,34 @@ public static class QuestionMapper
};
}
public static QuestionBase QuestionUpdateToModel(QuestionCreateDto dto, int surveyId, int questionId)
{
return dto.QuestionType.ToLower() switch
{
"textquestion" => new TextQuestion
{
Id = questionId,
Title = dto.Title,
SurveyId = surveyId,
},
"singleanswerquestion" => new SingleAnswerQuestion
{
Id = questionId,
Title = dto.Title,
SurveyId = surveyId,
AnswerVariants = [],
},
"multipleanswerquestion" => new MultipleAnswerQuestion
{
Id = questionId,
Title = dto.Title,
SurveyId = surveyId,
AnswerVariants = []
},
_ => throw new BadRequestException("Unknown question type")
};
}
private static List<OutputAnswerVariantDto> AnswerVariantsToDto(IEnumerable<AnswerVariant> answerVariants)
{
return answerVariants.Select(av => new OutputAnswerVariantDto