示例#1
0
        public ActionResult RemoveRespondant(string userToken)
        {
            var context = new EsmContext();
            var list    = context.Answers.Where(x => x.RespondentKey == userToken).ToList();

            context.Answers.RemoveRange(list); context.SaveChanges();
            return(View());
        }
示例#2
0
        public ActionResult SaveSurvey(string userToken, string notificationId, int questionId, int answerId, string answerIdStr = "", string userInput = "", string culture = "en")
        {
            var context = new EsmContext(); var isOtherInput = false;

            if (answerIdStr.EndsWith(","))
            {
                answerIdStr = answerIdStr.Substring(0, answerIdStr.Length - 1);
            }
            if (userInput.EndsWith(","))
            {
                userInput = userInput.Substring(0, userInput.Length - 1);
            }
            var q      = context.Questionnairs.First(x => x.QuestionnairId == questionId);//q never be null
            var answer = new Answer {
                RespondentKey = userToken, NotificationId = notificationId, QuestionnairId = questionId, ChoiceId = answerId, ResponseDate = DateTime.Now
            };

            switch (q.QuestionType)
            {
            case QuestionType.MultipleChoice:
                //do something later
                break;

            case QuestionType.MultipleChoiceWithOtherInput:
                var multipleChoices = (from s in answerIdStr.Split(',') select int.Parse(s)).ToList();
                //do something later
                break;

            case QuestionType.MultiInput:
                //do something later
                break;

            default:
                //do something later
                break;
            }

            if (answerId != 0)
            {
                isOtherInput = context.Options.First(x => x.ChoiceId == answerId).IsUserInput;
            }
            if (!isOtherInput)
            {
                userInput = "";
            }
            int surveyType = 1; if (q != null)

            {
                surveyType = (int)q.SurveyType;
            }

            answer.ChoicesIdStr       = answerIdStr; answer.ChoiceId = answerId; answer.SurveyType = (int)q.SurveyType;
            answer.TheUserInputAnswer = userInput;
            context.Answers.Add(answer);
            context.SaveChanges();
            return(RedirectToAction("ConductSurvey", new { userToken = userToken, notificationId = notificationId, culture = culture }));
        }