fix changing question type
This commit is contained in:
parent
837f90db52
commit
e1f7540803
3 changed files with 22 additions and 2 deletions
|
|
@ -71,7 +71,8 @@ public class QuestionController : ControllerBase
|
|||
var question = QuestionMapper.QuestionUpdateToModel(dto, id);
|
||||
await _questionService.UpdateQuestionAsync(question);
|
||||
var updatedQuestion = await _questionService.GetQuestionByIdAsync(id);
|
||||
return Ok(updatedQuestion);
|
||||
var result = QuestionMapper.ModelToQuestionDto(updatedQuestion);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -69,16 +69,22 @@ public static class QuestionMapper
|
|||
{
|
||||
Id = questionId,
|
||||
Title = dto.Title,
|
||||
Discriminator = "TextQuestion",
|
||||
AnswerVariants = []
|
||||
},
|
||||
"singleanswerquestion" => new SingleAnswerQuestion
|
||||
{
|
||||
Id = questionId,
|
||||
Title = dto.Title,
|
||||
Discriminator = "SingleAnswerQuestion",
|
||||
AnswerVariants = []
|
||||
},
|
||||
"multipleanswerquestion" => new MultipleAnswerQuestion
|
||||
{
|
||||
Id = questionId,
|
||||
Title = dto.Title,
|
||||
Discriminator = "MultipleAnswerQuestion",
|
||||
AnswerVariants = []
|
||||
},
|
||||
_ => throw new BadRequestException("Unknown question type")
|
||||
};
|
||||
|
|
|
|||
|
|
@ -41,8 +41,21 @@ public class QuestionService : IQuestionService
|
|||
|
||||
question.SurveyId = questionBase.SurveyId;
|
||||
|
||||
// Если изменился тип вопроса (Discriminator), используем новый тип
|
||||
if (questionBase.Discriminator != question.Discriminator)
|
||||
{
|
||||
// Удаляем старый вопрос
|
||||
await _questionRepository.DeleteAsync(questionBase.Id);
|
||||
|
||||
// Добавляем новый с тем же ID
|
||||
await _questionRepository.AddAsync(question);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Если тип не меняется, просто обновляем
|
||||
await _questionRepository.UpdateAsync(question);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteQuestionAsync(int id)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue