Example #1
0
        public bool DeleteQuestionAndAnswers(DeleteQuestionAndAnswersRequestModel requestModel)
        {
            var answerTable = requestModel
                              .AnswerIds
                              .Select(a => new Answer
            {
                intAnswerID = a
            });

            var success = _databaseController.Delete(answerTable);

            if (!success)
            {
                return(false);
            }
            var questionTable = requestModel
                                .QuestionIds
                                .Select(a => new Question
            {
                intQuestionId = a
            });

            success = _databaseController.Delete(questionTable);

            return(success);
        }
Example #2
0
        public IActionResult DeleteQuestionAndAnswers(EditQuestionAndAnswersViewModel viewModel)
        {
            var answerIds = new List <int>();

            foreach (var question in viewModel.QuestionsAndAnswers.Where(a => a.Delete))
            {
                answerIds.AddRange(question.Answers.Select(a => a.AnswerId));
            }

            var requestModel = new DeleteQuestionAndAnswersRequestModel
            {
                QuestionIds = viewModel.QuestionsAndAnswers.Where(a => a.Delete).Select(a => a.Id),
                AnswerIds   = answerIds
            };
            var content = JsonConvert.SerializeObject(requestModel);
            var success = _webserviceProvider.PostDataFromWebService <bool>(Controllers.Edit.ToString(), "DeleteQuestionWithAnswer", content);

            return(RedirectToAction("EditQuestions"));
        }
 public bool DeleteQuestionAndAnswers(DeleteQuestionAndAnswersRequestModel requestModel)
 {
     return(_editHandler.DeleteQuestionAndAnswers(requestModel));
 }