Esempio n. 1
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"));
        }
Esempio n. 2
0
        public IActionResult EditQuestions()
        {
            if (!CheckLoggedIn())
            {
                return(RedirectToAction("Login", "Login"));
            }

            var categories = _webserviceProvider.GetDataFromWebService <IEnumerable <CategoryModel> >(Controllers.Edit.ToString(), "AllCategories");
            var questions  = _webserviceProvider.GetDataFromWebService <IEnumerable <QuestionModel> >(Controllers.Edit.ToString(), "AllQuestions");
            var answers    = _webserviceProvider.GetDataFromWebService <IEnumerable <AnswerModel> >(Controllers.Edit.ToString(), "AllAnswers");
            var viewModel  = new EditQuestionAndAnswersViewModel
            {
                Categories          = categories.ToList(),
                QuestionsAndAnswers = questions.Select(a => new EditQuestionAndAnswerViewModel
                {
                    Name = a.Question,
                    SelectedCategoryId = a.CategoryId,
                    Answers            = answers.Where(b => b.QuestionId == a.QuestionId).ToList(),
                    Id = a.QuestionId
                }).ToList()
            };

            return(View(viewModel));
        }