Exemple #1
0
        public async Task <JsonResult> RemoveSurvey(string id)
        {
            var survey = surveyRepository.GetItems().Include(x => x.SurveyQuestion).ThenInclude(y => y.Options).ThenInclude(z => z.OptionsForAnswers).Include(x => x.SurveyQuestion).ThenInclude(a => a.UserAnswers).FirstOrDefault(x => x.Id == id);

            if (survey == null)
            {
                return(Json(null));
            }
            foreach (var question in survey.SurveyQuestion.ToList())
            {
                foreach (var option in question.Options.ToList())
                {
                    foreach (var optionsforanswer in option.OptionsForAnswers.ToList())
                    {
                        await optionsForAnswerRepository.Delete(optionsforanswer);
                    }
                    await optionRepository.Delete(option);
                }
                foreach (var useranswers in question.UserAnswers.ToList())
                {
                    await userAnswerRepository.Delete(useranswers);
                }
                await surveyQuestionRepository.Delete(question);
            }
            await surveyRepository.Delete(survey);

            return(new JsonResult(id));
        }
        public async Task <bool> DeleteQuestionsById(Guid id)
        {
            try
            {
                var question = await _questionRepository.Get(id);

                if (question == null)
                {
                    return(false);
                }

                await _questionRepository.Delete(question);

                return(true);
            }
            catch (Exception e)
            {
                _logger.Error(e, "SurveyQuestionManagementService.DeleteQuestionsById");
                throw;
            }
        }