NuSurvey.Web.Controllers.SurveyResponseController.StartSurvey C# (CSharp) Method

StartSurvey() public method

#3 Start or continue a survey with one question at a time GET: /SurveyResponse/StartSurvey/5
public StartSurvey ( int id ) : System.Web.Mvc.ActionResult
id int Survey ID
return System.Web.Mvc.ActionResult
        public ActionResult StartSurvey(int id)
        {
            var userId = string.Empty;
            var guid = Guid.NewGuid();
            if (!string.IsNullOrWhiteSpace(CurrentUser.Identity.Name))
            {
                userId = CurrentUser.Identity.Name.ToLower();
            }
            else
            {
                userId = guid.ToString();
            }

            var survey = Repository.OfType<Survey>().GetNullableById(id);
            if (survey == null || !survey.IsActive)
            {
                Message = "Survey not found or not active.";
                return this.RedirectToAction<ErrorController>(a => a.Index());
            }

            #region Check To See if there are enough available Categories
            if (GetCountActiveCategoriesWithScore(survey) < 3)
            {
                Message = "Survey does not have enough active categories to complete survey.";
                return this.RedirectToAction<ErrorController>(a => a.Index());
            }
            #endregion Check To See if there are enough available Categories

            var cannotContinue = false;

            var pendingExists = _surveyResponseRepository.Queryable
                .Where(a => a.Survey.Id == id && a.IsPending && a.UserId == userId).FirstOrDefault();
            if (pendingExists != null)
            {
                foreach (var answer in pendingExists.Answers)
                {
                    if (!answer.Category.IsCurrentVersion)
                    {
                        Message =
                            "The unfinished survey's questions have been modified. Unable to continue. Delete survey and start again.";
                        cannotContinue = true;
                        break;
                    }
                }
                if (!cannotContinue)
                {
                    Message = "Unfinished survey found.";
                }
            }

            ViewBag.surveyimage = string.Format("{0}-survey", survey.ShortName.ToLower().Trim());

            var viewModel = SingleAnswerSurveyResponseViewModel.Create(Repository, survey, pendingExists);
            viewModel.CannotContinue = cannotContinue;
            if (!string.IsNullOrWhiteSpace(CurrentUser.Identity.Name))
            {
                viewModel.PublicGuid = null;
            }
            else
            {
                viewModel.PublicGuid = guid;
            }

            return View(viewModel);
        }

Same methods

SurveyResponseController::StartSurvey ( int id, SurveyResponse surveyResponse, System.Guid publicGuid ) : System.Web.Mvc.ActionResult