Пример #1
0
        public ActionResult Index(SurveyViewModel model)
        {
            try
            {
                Entry entry = new Entry();
                entry.SurveyID = model.SurveyId;
                if (User.Identity.Name != "")
                {
                    entry.UserID = User.Identity.Name;
                }
                entry.Date = DateTime.Now;

                int entryid = _repository.CreateEntry(entry);

                foreach (var question in model.Questions)
                {
                    Response r = new Response();
                    r.Date = DateTime.Now;
                    r.Question = question.QuestionId;
                    r.Answer = question.SelectedAnswer;
                    r.Survey = model.SurveyId;
                    r.UserID = User.Identity.Name;
                    r.Entry = entryid;
                    _repository.CreateResponse(r);
                }
            }
            catch (Exception e)
            {
                TempData["Message"] = e;
                return View("Error");
            }

            TempData["Message"] = "Good times.";
            return View("Thanks");
        }
Пример #2
0
        public ActionResult Index(int id)
        {
            try
            {

            Survey survey = _repository.GetSurvey(id);

            if (survey.Live != 1 && survey.Approved != 1)
            {
                TempData["Message"] =
                    "This survey is not active. If this is your survey, it may be pending approval, or you may have it still as a draft. Check your dashboard.";
                return View("Error");
            }

            SurveyViewModel vm = new SurveyViewModel();
            vm.SurveyId = id;
            vm.Title = survey.Title;

            vm.Questions = new List<QuestionViewModel>();

            foreach (Question question in _repository.GetQuestions(id))
            {
                QuestionViewModel qvm = new QuestionViewModel();
                qvm.QuestionId = question.ID;
                qvm.Text = question.Text;
                qvm.Answers = new List<AnswerViewModel>();
                foreach (var answer in _repository.GetAnswers(question.ID))
                {
                    AnswerViewModel avm = new AnswerViewModel();
                    avm.AnswerId = answer.ID;
                    avm.Text = answer.Text;
                    qvm.Answers.Add(avm);
                }
                vm.Questions.Add(qvm);
            }
            return View(vm);
            }
            catch (Exception)
            {
                TempData["Message"] =
            "This survey is not active. If this is your survey, it may be pending approval, or you may have it still as a draft. Check your dashboard.";
                return View("Error");
            }
        }