public ActionResult Index(string surveyId, string addNewFormId, string editForm, string cancel) { // Assign "editForm" parameter to a less confusing name. // editForm contains the responseId of the record being edited. string editResponseId = editForm; int userId = GetIntSessionValue(UserSession.Key.UserId); string userName = GetStringSessionValue(UserSession.Key.UserName); bool isMobileDevice = this.Request.Browser.IsMobileDevice; FormsAuthentication.SetAuthCookie("BeginSurvey", false); bool isEditMode = false; if (isMobileDevice == true) { isMobileDevice = Epi.Cloud.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString()); } bool isAndroid = this.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0; if (!string.IsNullOrEmpty(/*FromURL*/ cancel)) { int pageNumber; int.TryParse(/*FromURL*/ cancel, out pageNumber); Dictionary <string, int> surveyPagesList = GetSessionValue <Dictionary <string, int> >(UserSession.Key.RelateButtonPageId); if (surveyPagesList != null) { pageNumber = surveyPagesList[this.Request.Form["Parent_Response_Id"].ToString()]; } return(RedirectToRoute(new { Controller = "Survey", Action = "Index", responseid = this.Request.Form["Parent_Response_Id"].ToString(), PageNumber = pageNumber })); } if (string.IsNullOrEmpty(/*FromURL*/ editResponseId) && string.IsNullOrEmpty(/*FromURL*/ addNewFormId) && !IsSessionValueNull(UserSession.Key.EditResponseId)) { editResponseId = GetStringSessionValue(UserSession.Key.EditResponseId); } if (!string.IsNullOrEmpty(editResponseId)) { if (IsSessionValueNull(UserSession.Key.RootResponseId)) { SetSessionValue(UserSession.Key.RootResponseId, editResponseId); } isEditMode = true; SetSessionValue(UserSession.Key.IsEditMode, isEditMode); SurveyAnswerDTO surveyAnswer = GetSurveyAnswer(editResponseId, GetStringSessionValue(UserSession.Key.RootFormId)); if (!IsSessionValueNull(UserSession.Key.RecoverLastRecordVersion)) { surveyAnswer.RecoverLastRecordVersion = GetBoolSessionValue(UserSession.Key.RecoverLastRecordVersion); } // string childRecordId = GetChildRecordId(surveyAnswer); //return RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = surveyAnswer.ParentResponseId, PageNumber = 1, Edit = "Edit" }); return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = editResponseId, PageNumber = 1, Edit = "Edit" })); } //create the responseid Guid responseId = Guid.NewGuid(); if (IsSessionValueNull(UserSession.Key.RootResponseId)) { SetSessionValue(UserSession.Key.RootResponseId, responseId); } var rootResponseId = GetStringSessionValue(UserSession.Key.RootResponseId); TempData[TempDataKeys.ResponseId] = responseId.ToString(); int orgId = GetIntSessionValue(UserSession.Key.CurrentOrgId); var responseContext = InitializeResponseContext(formId: /*FromURL*/ addNewFormId, responseId: responseId.ToString(), parentResponseId: this.Request.Form["Parent_Response_Id"].ToString(), isNewRecord: !isEditMode); // create the first survey response SurveyAnswerDTO surveyAnswerDTO = _surveyFacade.CreateSurveyAnswer(responseContext); List <FormsHierarchyDTO> formsHierarchy = GetFormsHierarchy(); SurveyInfoModel surveyInfoModel = GetSurveyInfo(surveyAnswerDTO.SurveyId, formsHierarchy); MetadataAccessor metadataAccessor = surveyInfoModel as MetadataAccessor; // set the survey answer to be production or test surveyAnswerDTO.IsDraftMode = surveyInfoModel.IsDraftMode; MvcDynamicForms.Form form = _surveyFacade.GetSurveyFormData(surveyAnswerDTO.SurveyId, 1, surveyAnswerDTO, isMobileDevice, null, formsHierarchy, isAndroid); TempData[TempDataKeys.Width] = form.Width + 100; var formDigest = metadataAccessor.GetFormDigest(surveyAnswerDTO.SurveyId); string checkcode = formDigest.CheckCode; FormResponseDetail responseDetail = surveyAnswerDTO.ResponseDetail; form.FormCheckCodeObj = form.GetCheckCodeObj(MetadataAccessor.GetFieldDigests(surveyAnswerDTO.SurveyId), responseDetail, checkcode); ///////////////////////////// Execute - Record Before - start////////////////////// Dictionary <string, string> ContextDetailList = new Dictionary <string, string>(); EnterRule functionObject_B = (EnterRule)form.FormCheckCodeObj.GetCommand("level=record&event=before&identifier="); SurveyResponseBuilder surveyResponseBuilder = new SurveyResponseBuilder(_requiredList); if (functionObject_B != null && !functionObject_B.IsNull()) { try { PageDigest[] pageDigests = form.MetadataAccessor.GetCurrentFormPageDigests(); responseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigests); SetSessionValue(UserSession.Key.RequiredList, surveyResponseBuilder.RequiredList); _requiredList = surveyResponseBuilder.RequiredList; form.RequiredFieldsList = _requiredList; functionObject_B.Context.HiddenFieldList = form.HiddenFieldsList; functionObject_B.Context.HighlightedFieldList = form.HighlightedFieldsList; functionObject_B.Context.DisabledFieldList = form.DisabledFieldsList; functionObject_B.Context.RequiredFieldList = form.RequiredFieldsList; functionObject_B.Execute(); // field list form.HiddenFieldsList = functionObject_B.Context.HiddenFieldList; form.HighlightedFieldsList = functionObject_B.Context.HighlightedFieldList; form.DisabledFieldsList = functionObject_B.Context.DisabledFieldList; form.RequiredFieldsList = functionObject_B.Context.RequiredFieldList; ContextDetailList = SurveyHelper.GetContextDetailList(functionObject_B); form = SurveyHelper.UpdateControlsValuesFromContext(form, ContextDetailList); _surveyFacade.UpdateSurveyResponse(surveyInfoModel, responseId.ToString(), form, surveyAnswerDTO, false, false, 0, orgId, userId, userName); } catch (Exception ex) { // do nothing so that processing // can continue } } else { PageDigest[] pageDigestArray = form.MetadataAccessor.GetCurrentFormPageDigests();// metadataAccessor.GetPageDigests(surveyInfoModel.SurveyId); surveyAnswerDTO.ResponseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigestArray); _requiredList = surveyResponseBuilder.RequiredList; SetSessionValue(UserSession.Key.RequiredList, _requiredList); form.RequiredFieldsList = _requiredList; _surveyFacade.UpdateSurveyResponse(surveyInfoModel, surveyAnswerDTO.ResponseId, form, surveyAnswerDTO, false, false, 0, orgId, userId, userName); } surveyAnswerDTO = (SurveyAnswerDTO)formsHierarchy.SelectMany(x => x.ResponseIds).FirstOrDefault(z => z.ResponseId == surveyAnswerDTO.ResponseId); ///////////////////////////// Execute - Record Before - End////////////////////// return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = responseId, PageNumber = 1 })); }