예제 #1
0
        public virtual ActionResult SOC29()
        {
            var soc29 = _questionnairesRepository.GetByType(KeyType.SOC29);
            var model = new SOC29ViewModel();

            model.SetQuestionnaire(soc29);
            model.SelectedValues      = new List <int>();
            model.UnselectedQuestions = new List <int>();

            return(View(model));
        }
예제 #2
0
        public virtual ActionResult SOC29(SOC29ViewModel model)
        {
            if (model.Questions.All(x => x.AnswerId > 0))
            {
                var results = (List <Result>)Session[_resultsSessionKey];
                if (results == null)
                {
                    return(RedirectToAction(MVC.Application.Survey.IntervieweeInfo()));
                }

                results.RemoveAll(x => x.QuestionnaireId == model.QuestionnaireId);
                results.AddRange(model.Questions
                                 .Select(x => new Result()
                {
                    QuestionnaireId = model.QuestionnaireId,
                    QuestionId      = x.QuestionId,
                    AnswerId        = x.AnswerId
                }));

                Session[_resultsSessionKey] = results;

                return(RedirectToAction(MVC.Application.Survey.IZZ()));
            }
            else
            {
                if (model.Questions.Any(x => x.AnswerId == 0))
                {
                    ModelState.AddModelError("", "Należy odpowiedzieć na wszystkie pytnia");
                }

                var selectedValues      = model.Questions.Where(x => x.AnswerId > 0).Select(x => x.AnswerId).ToList();
                var unselectedQuestions = model.Questions.Where(x => x.AnswerId == 0).Select(x => x.QuestionId).ToList();

                model.SetQuestionnaire(_questionnairesRepository.GetByType(KeyType.SOC29));

                model.SelectedValues      = selectedValues;
                model.UnselectedQuestions = unselectedQuestions;

                return(View(model));
            }
        }