public void DeleteAnswer(int answerId) { var answer = answerRepo.GetAnswerById(answerId); GeneralHelpers.ThrowIfNull(answer); answerRepo.DeleteAnswer(answer); }
public async Task <ActionResult> DeleteQuiz(string Id, IFormCollection collection, Quiz quiz) { try { // TODO: Add update logic here if (Id == null) { return(RedirectToAction("Quizzes")); } //delete quiz await quizRepo.DeleteQuiz(Guid.Parse(Id)); //delete questions var questions = await questionRepo.GetQuestionsByQuizAsync(Guid.Parse(Id)); foreach (var item in questions) { //get answer var answer = await answerRepo.GetAnswerByQuestionAsync(item.QuestionId); //delete answer await answerRepo.DeleteAnswer(answer.AnswerID); //get choices var choices = await choiceRepo.GetChoicesAsync(item.QuestionId); foreach (var choice in choices) { await choiceRepo.DeleteChoice(choice.ChoiceID); } } return(RedirectToAction("Quizzes")); } catch (Exception ex) { Debug.WriteLine($"update error. {ex.Message}"); ModelState.AddModelError("", "Update actie mislukt." + ex.InnerException.Message); return(View(quiz)); } }