コード例 #1
0
        public ActionResult Create(long id)
        {
            //  TODO:   Refactor this to a Mapping class, probably not an Action Filter as there are repository calls required.
            AddQuestionsViewModel question = new AddQuestionsViewModel();
            question.id = id;

            Survey relatedSurvey = _surveyRepository.GetSurvey(id);
            question.id = relatedSurvey.SurveyId;
            question.Title = relatedSurvey.Title;
            question.CategoryDescription = _categoryRepository.GetCategory(relatedSurvey.Category.CategoryId).Description;

            question.LikertTemplates = new SelectList(_templateRepository.GetLikertTemplates(), "Id", "Title");

            return View(question);
        }
コード例 #2
0
        public ActionResult Create(AddQuestionsViewModel question)
        {
            if (ModelState.IsValid)
            {
                //  Map the info to a Question domain model.                            (USER INPUT)
                Question newQuestion = Mapper.Map<AddQuestionsViewModel, Question>(question);

                //  Add the related survey                                              (USER INPUT)
                newQuestion.Survey = _surveyRepository.GetSurvey(question.id);

                //  Create the Available from the selected TemplateResponses.           (USER SELECTION)
                var templateResponses = _templateRepository.GetLikertScaleResponses(question.LikertId).ToArray();
                newQuestion.AvailableResponses = Mapper.Map<TemplateResponse[], AvailableResponse[]>(templateResponses);

                //  Add the sequence number, unique within the survey                   (BUSINESS LOGIC)
                long seqNo = _questionRepository.GetLastSequenceNumber(question.id);
                newQuestion.SequenceNumber = ++seqNo;

                //  add the question to the model
                long id = _questionRepository.AddQuestion(newQuestion);

                return RedirectToAction("Create", new { surveyId = question.id });
            }
            else
            {
                //  Re-instate the reference values.
                Survey relatedSurvey = _surveyRepository.GetSurvey(question.id);
                question.id = relatedSurvey.SurveyId;
                question.Title = relatedSurvey.Title;
                question.CategoryDescription = _categoryRepository.GetCategory(relatedSurvey.Category.CategoryId).Description;

                question.LikertTemplates = new SelectList(_templateRepository.GetLikertTemplates(), "Id", "Title");
                return View(question);
            }
        }