NuSurvey.Web.Controllers.QuestionController.Edit C# (CSharp) Method

Edit() public method

#4 GET: /Question/Edit/5
public Edit ( int id, int surveyId, int categoryId ) : System.Web.Mvc.ActionResult
id int Question Id
surveyId int
categoryId int
return System.Web.Mvc.ActionResult
        public ActionResult Edit(int id, int surveyId, int? categoryId)
        {
            var survey = Repository.OfType<Survey>().GetNullableById(surveyId);
            if (survey == null)
            {
                Message = "Survey Not Found";
                return this.RedirectToAction<ErrorController>(a => a.Index());
            }

            var question = _questionRepository.GetNullableById(id);
            if (question == null)
            {
                Message = "Question Not Found.";
                return this.RedirectToAction<SurveyController>(a => a.Edit(survey.Id));
            }

            if (question.Survey.Id != survey.Id)
            {
                Message = "Question not related to current survey";
                return this.RedirectToAction<ErrorController>(a => a.Index());
            }

            if (!question.Category.IsCurrentVersion)
            {
                Message = "Question's related category is not current version";
                return this.RedirectToAction<ErrorController>(a => a.Index());
            }

            var viewModel = QuestionViewModel.Create(Repository, survey);
            viewModel.Question = question;
            if (categoryId != null)
            {
                var category = Repository.OfType<Category>().GetNullableById(categoryId.Value);
                viewModel.Category = category;
            }

            foreach (var resp in
                question.Responses.OrderBy(a => a.Order).Select(response => new ResponsesParameter {Value = response.Value, Score = response.Score, ResponseId = response.Id,  Remove = !response.IsActive}))
            {
                viewModel.Responses.Add(resp);
            }

            viewModel.UniqueTags = Repository.OfType<PhotoTag>().Queryable.OrderBy(b => b.Name).Select(a => a.Name).Distinct().ToList();

            return View(viewModel);
        }

Same methods

QuestionController::Edit ( int id, int surveyId, int categoryId, Question question, ResponsesParameter response ) : System.Web.Mvc.ActionResult