Пример #1
0
        public ActionResult Create()
        {
            CreateSurveyViewModel survey = new CreateSurveyViewModel();
            survey.CategoryList = new SelectList(_categoryRepository.GetAll(), "CategoryId", "Description");

            return View(survey);
        }
Пример #2
0
        public ActionResult Create(CreateSurveyViewModel survey)
        {
            if (ModelState.IsValid)
            {
                //  TODO: Refactor code to a mapper method (next 4 lines);
                var newSurvey = Core.Factories.SurveyFactory.CreateSurvey();

                //  Add the info enter by user
                newSurvey.Title = survey.Title;
                //  Add the Category, from the selected one, and the User from the HttpContext
                //  so we can add the new survey.  These values are not availble within the
                //  Business model
                newSurvey.User = _userRepository.GetUserByName(HttpContext.User.Identity.Name);
                newSurvey.Category = _categoryRepository.GetCategory(survey.CategoryId);

                //  Add the new survey to the model, and retrieve its key so we can progress to the Add Questions
                long newSurveyid = _surveyRepository.CreateSurvey(newSurvey);

                return RedirectToAction("Create", "Question", new { id = newSurveyid });
            }
            else
            {
                //  Get the categories again, they're not retained between pages.
                survey.CategoryList = new SelectList(_categoryRepository.GetAll(), "CategoryId", "Description");
                return View(survey);
            }
        }