示例#1
0
        public ActionResult StartSurvey(string actives, string activeLog, string activeRem, QuestionVM model)
        {
            Security           active = session(actives, activeLog, activeRem);
            SecurityController Active = new SecurityController(active);

            if (!(IsLoggedIn(Active).CheckLogin() || !ModelState.IsValid))
            {
                return(RedirectToAction("Index", "Home"));
            }

            SurveyQuestionVM      surveyQuestionVM = new SurveyQuestionVM(active);
            AnswersController     aController      = new AnswersController();
            EnvironmentController eController      = new EnvironmentController();
            string userId = Active.GetID();

            if (Request.Form["btnEditSurvey"] != null)
            {
                Answer a = aController.GetAnswer(userId, int.Parse(Request.Form["btnEditSurvey"]));

                surveyQuestionVM.QuestionText = eController.GetQuestionText(1);
                surveyQuestionVM.AId          = a.AId;
                surveyQuestionVM.QId          = 1;

                surveyQuestionVM.ProgramName = a.programName;
            }
            else
            {
                surveyQuestionVM.QuestionText      = eController.GetQuestionText(1);
                surveyQuestionVM.AId               = aController.GetNextAId(userId);
                surveyQuestionVM.QId               = 1;
                surveyQuestionVM.NumberofQuestions = eController.GetQuestionCount();
                surveyQuestionVM.ProgramName       = model.Name;
            }

            using (var context = new DBAContext())
            {
                Answer CheckAnswer = (from t in context.Answers where ((userId == t.UId) & (1 == t.QId) & (surveyQuestionVM.AId == t.AId)) select t).FirstOrDefault();

                if (CheckAnswer != null)
                {
                    surveyQuestionVM.Value = CheckAnswer.Value;
                }
            }
            //sets up the state of the buttons
            surveyQuestionVM.NumberofQuestions = eController.GetQuestionCount();
            surveyQuestionVM.AnsweredQuestions = GetAnsweredList(userId, surveyQuestionVM.AId);
            surveyQuestionVM.DisableQuestion   = GetDisable(userId, surveyQuestionVM.AId, surveyQuestionVM.AnsweredQuestions);
            if (surveyQuestionVM.DisableQuestion != null)
            {
                DeleteAnswer(userId, surveyQuestionVM.AId, surveyQuestionVM.DisableQuestion);
            }

            ModelState.Clear();

            return(View("SurveyQuestions", surveyQuestionVM));
        }