Exemplo n.º 1
0
        public UpdateResult Delete(int id)
        {
            UpdateResult result = new UpdateResult();

            try
            {
                Model.Models.Survey survey = _surveyRepository.GetSingleById(id);
                foreach (Question question in survey.Questions)
                {
                    foreach (Answer answer in question.Answers)
                    {
                        _answerRepository.Delete(answer);
                    }
                    _questionRepository.Delete(question);
                }
                _surveyRepository.Delete(survey);
            }
            catch (Exception exception)
            {
                AddLogError(exception,
                            $"Error when delete survey {id}");
                result.State       = 4;
                result.KeyLanguage = UpdateResult.ERROR_WHEN_UPDATED;
            }
            if (result.State == 1)
            {
                Save();
            }
            return(result);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public IActionResult Delete(int id)
        {
            var survey = _surveyRepository.GetById(id);

            _surveyRepository.Delete(survey);

            return(RedirectToAction("List"));
        }
Exemplo n.º 4
0
 public bool Delete(Survey element)
 {
     try
     {
         return(_surveyRepo.Delete(element));
     }
     catch (Exception ex)
     {
         //Maybe log
         return(false);
     }
 }
Exemplo n.º 5
0
        public async Task GivenId_WhenDelete_ThenDeleteSuccessful()
        {
            //?Given
            var id = "1234";

            _mockService.Setup(x => x.Delete <SurveyEntity>(It.IsAny <string>(), id))
            .Verifiable();

            //?When
            await _surveyRepository.Delete(id);

            //?THen
            _mockService.Verify();
        }
Exemplo n.º 6
0
        public bool Delete(Survey item)
        {
            if (item == null)
            {
                return(false);
            }

            var findsurveyid = _repository.Get(item.Id);

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

            bool result = _repository.Delete(item);

            return(result);
        }
Exemplo n.º 7
0
        public async Task <bool> DeleteSurveyById(Guid id)
        {
            try
            {
                var survey = await _surveyRepository.Get(id);

                if (survey == null)
                {
                    return(false);
                }
                await _surveyRepository.Delete(survey);

                return(true);
            }
            catch (Exception e)
            {
                _logger.Error(e, "SurveyManagementService.DeleteSurveyById");
                throw;
            }
        }
Exemplo n.º 8
0
 public async Task Delete(string id)
 {
     await _repository.Delete(id);
 }