public async Task <ActionResult> Delete(Guid id, IFormCollection collection)
        {
            try
            {
                if (id == null)
                {
                    throw new Exception("Bad Delete Request.");
                }
                IEnumerable <Questions> list = await questionsRepo.GetQuestionsByQuiz(id);

                foreach (Questions question in list)
                {
                    await questionsRepo.Delete(question.QuestionID);
                }
                await quizrepo.Delete(id);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                Debug.WriteLine($"Delete error. ");
                ModelState.AddModelError(String.Empty, "Delete failed.");
                return(View());
            }
        }
Exemple #2
0
        public async Task <IActionResult> Delete(int id)
        {
            if (_repo.QuestionsAnswerExists(id))
            {
                return(Content("Nie mozna usunąć pytania - posiada odpowiedzi."));
            }
            await _repo.Delete(id);

            return(Content("success"));
        }
        public async Task <ActionResult> DeleteAsync(Guid id, IFormCollection collection)
        {
            try
            {
                var Quiz = await quizrepo.GetQuizByQuestionID(id);

                if (id == null)
                {
                    throw new Exception("Bad Delete Request.");
                }
                await questionsRepo.Delete(id);

                return(RedirectToAction("Index", "QuestionsAnswers", new { id = Quiz.QuizID }));
            }
            catch (Exception)
            {
                Debug.WriteLine($"Delete error. ");
                ModelState.AddModelError(String.Empty, "Delete failed.");
                return(View());
            }
        }
        public async Task <IActionResult> Delete(Guid id)
        {
            await questionsRepo.Delete(id);

            return(Ok("DELETE was succesfull"));
        }