I have a method that adds some data to my database, it worked fine a while ago but now it has just stopped working. I found out with debugging that my async method gets called but then just stops in the middle and the Answers are never getting added:
private async Task CreateNewQuestion()
{
if (newQuestion.QuestionType is null)
{
noType = true;
return;
}
else if (Answers.Count == 0)
{
noAnswer = true;
return;
}
else if (newQuestion.QuestionType is not null)
{
List<Question> questioncount = new List<Question>();
questioncount = await questionRepo.GetQuestionByQuizId(QuizId);
_order = questioncount.Count + 1;
newQuestion.QuestionOrderId = _order;
newQuestion.AnswerType = _answerType;
newQuestion.QuestionUrl = _questionUrlConverted;
await questionRepo.AddQuestionWithAnswers(newQuestion, Answers); <-- THIS IS WHERE THE METHOD GETS CALLED
noType = false;
questions = await questionRepo.GetQuestionByQuizId(QuizId);
var quiz = quizRepo.GetQuizById(QuizId);
Navigation.NavigateTo($"/Quiz/AddQuestionWithId/{QuizId}", true);
}
}
and here is the method:
public async Task AddQuestionWithAnswers(Question newQuestion, List<Answer> answers)
{
if(newQuestion is not null && answers.Count > 0)
{
_context.Questions.Add(newQuestion);
await _context.SaveChangesAsync(); <-- THIS IS WHERE IT JUST STOPS TO EXECUTE
var answerQuestionItem = await GetQuestionById(newQuestion.QuestionId);
if(answerQuestionItem is not null)
{
foreach(var answer in answers)
{
answer.Question = answerQuestionItem;
_context.Answers.Add(answer);
await _context.SaveChangesAsync();
}
}
}
}
It also doesn't even go back to the method that called the method, just to my razor component and nothing happens. Any ideas how I can fix this?