public ActionResult AddOrUpdate(QuestionCategoriesViewModelContainer categoryModel)
        {
            int parentCategory = 0;

            if (String.IsNullOrEmpty(categoryModel.QuestionCategoryViewModel.Parent))
            {
                parentCategory = _categoryService.GetQuestionCategory(categoryModel.QuestionCategoryViewModel.Parent).Id;
            }

            QuestionCategory category = new QuestionCategory()
            {
                Id         = categoryModel.QuestionCategoryViewModel.Id,
                Name       = categoryModel.QuestionCategoryViewModel.Name,
                ParentID   = parentCategory,
                AnswerType = categoryModel.QuestionCategoryViewModel.QuestionAnswerType
            };

            List <QuestionAnswer> questionAnswers = new List <QuestionAnswer>();

            foreach (QuestionAnswerViewModel model in categoryModel.QuestionAnswerViewModel)
            {
                questionAnswers.Add(_mapper.Map <QuestionAnswer>(model));
            }

            category.QuestionAnswers = questionAnswers;
            _categoryService.AddOrUpdate(category);

            return(RedirectToAction("Index", categoryModel));
        }
        public ActionResult Index(int?id)
        {
            QuestionCategoriesViewModelContainer model = new QuestionCategoriesViewModelContainer();

            if (id.HasValue)
            {
                QuestionCategory category = _categoryService.GetQuestionCategory(id.Value);
                model = MapCategoryToCategoryViewModel(category);
            }

            return(View(model));
        }
 public ActionResult RemoveQuestionAnswer(QuestionCategoriesViewModelContainer model)
 {
     if (!String.IsNullOrEmpty(model.QuestionAnswerHelper.AnswerToRemove))
     {
         QuestionAnswerViewModel existingAnswer = model.QuestionAnswerViewModel.Where(qa => qa.Value == model.QuestionAnswerHelper.AnswerToRemove.Trim()).FirstOrDefault();
         if (existingAnswer != null)
         {
             model.QuestionAnswerViewModel.Remove(existingAnswer);
         }
     }
     model.QuestionAnswerHelper.AnswerToAdd    = "";
     model.QuestionAnswerHelper.AnswerToRemove = "";
     ModelState.Clear();
     return(View("Index", model));
 }
        private QuestionCategoriesViewModelContainer MapCategoryToCategoryViewModel(QuestionCategory category)
        {
            QuestionCategoriesViewModelContainer model = new QuestionCategoriesViewModelContainer();

            if (category != null)
            {
                model.QuestionCategoryViewModel = _mapper.Map <QuestionCategoryViewModel>(category);
                foreach (QuestionAnswer answer in _categoryService.GetAnswers(category.Id).ToList())
                {
                    QuestionAnswerViewModel answerModel = _mapper.Map <QuestionAnswerViewModel>(answer);
                    answerModel.IsPrimary = answer.Questions.Any();
                    model.QuestionAnswerViewModel.Add(answerModel);
                }
            }

            return(model);
        }
        public ActionResult AddQuestionAnswer(QuestionCategoriesViewModelContainer model)
        {
            if (!String.IsNullOrEmpty(model.QuestionAnswerHelper.AnswerToAdd))
            {
                QuestionAnswerViewModel answerModel = new QuestionAnswerViewModel()
                {
                    CategoryID = model.QuestionCategoryViewModel.Id,
                    Value      = model.QuestionAnswerHelper.AnswerToAdd,
                    IsPrimary  = false
                };

                model.QuestionAnswerViewModel.Add(answerModel);
            }
            model.QuestionAnswerHelper.AnswerToAdd    = "";
            model.QuestionAnswerHelper.AnswerToRemove = "";
            ModelState.Clear();
            return(View("Index", model));
        }
 public ActionResult Index(QuestionCategoriesViewModelContainer model)
 {
     return(View(model));
 }