Exemplo n.º 1
0
        public void DeleteQuiz(int quizId)
        {
            var subjectQuiz = quizRepo.GetQuizById(quizId);

            GeneralHelpers.ThrowIfNull(subjectQuiz);
            quizRepo.DeleteQuiz(subjectQuiz);
        }
        public async Task <IActionResult> DeleteQuiz(Guid id, IFormCollection collection)
        {
            try
            {
                await quizRepo.DeleteQuiz(id);

                return(RedirectToAction(nameof(Quizzes)));
            }
            catch (Exception exc)
            {
                return(RedirectToAction(nameof(Quizzes), new { exc = exc.Message }));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var model = await quizRepo.GetQuizForIdAsync(id);

            if (model != null)
            {
                await quizRepo.DeleteQuiz(id);

                return(Ok("Quiz deleted"));
            }
            else
            {
                return(BadRequest("There is no quiz with this id..."));
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Delete(Guid id, IFormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                if (id == null)
                {
                    throw new Exception("Bad Delete Request");
                }
                await quizRepo.DeleteQuiz(id);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Delete error. " + ex.Message);
                ModelState.AddModelError(String.Empty, "Delete failed");
                return(View());
            }
        }
Exemplo n.º 5
0
        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));
            }
        }