public ActionResult Index(string surveyId, string addNewFormId, string editForm) { // Assign "editForm" parameter to a less confusing name. // editForm contains the responseId of the record being edited. string editResponseId = editForm; bool isNewRecord; int orgId = GetIntSessionValue(UserSession.Key.CurrentOrgId); int userId = GetIntSessionValue(UserSession.Key.UserId); string userName = GetStringSessionValue(UserSession.Key.UserName); SetSessionValue(UserSession.Key.FormValuesHasChanged, string.Empty); var editResponseIdFromSession = GetStringSessionValue(UserSession.Key.EditResponseId); if (string.IsNullOrEmpty(editResponseId) && editResponseIdFromSession != null) { editResponseId = editResponseIdFromSession; } if (!string.IsNullOrEmpty(editResponseId) && string.IsNullOrEmpty(addNewFormId)) { // ------------------------------- // Edit Existing Record // ------------------------------- isNewRecord = false; SetSessionValue(UserSession.Key.RootResponseId, editResponseId); SetSessionValue(UserSession.Key.IsEditMode, true); SurveyAnswerDTO surveyAnswerDTO = GetSurveyAnswer(editResponseId, GetStringSessionValue(UserSession.Key.RootFormId)); SetSessionValue(UserSession.Key.RequestedViewId, surveyAnswerDTO.ViewId); surveyAnswerDTO.RecoverLastRecordVersion = GetBoolSessionValue(UserSession.Key.RecoverLastRecordVersion); RemoveSessionValue(UserSession.Key.RecoverLastRecordVersion); return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = editResponseId, PageNumber = 1, surveyid = surveyAnswerDTO.SurveyId, Edit = "Edit" })); } // ------------------------------- // Add New Record // ------------------------------- isNewRecord = true; SetSessionValue(UserSession.Key.IsEditMode, false); bool isMobileDevice = this.Request.Browser.IsMobileDevice; if (isMobileDevice == false) { isMobileDevice = Epi.Cloud.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString()); } FormsAuthentication.SetAuthCookie("BeginSurvey", false); //create the responseid Guid responseId = Guid.NewGuid(); TempData[TempDataKeys.ResponseId] = responseId.ToString(); // create the first survey response // Epi.Cloud.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(surveyModel.SurveyId, ResponseID.ToString()); SetSessionValue(UserSession.Key.RootFormId, addNewFormId); var rootResponseId = responseId; SetSessionValue(UserSession.Key.RootResponseId, rootResponseId); var responseContext = InitializeResponseContext(formId: addNewFormId, responseId: responseId.ToString(), isNewRecord: true) as ResponseContext; SurveyAnswerDTO surveyAnswer = _surveyFacade.CreateSurveyAnswer(responseContext); surveyId = /*FromURL*/ surveyId ?? surveyAnswer.SurveyId; // Initialize the Metadata Accessor MetadataAccessor.CurrentFormId = surveyId; MvcDynamicForms.Form form = _surveyFacade.GetSurveyFormData(surveyAnswer.SurveyId, 1, surveyAnswer, isMobileDevice); SurveyInfoModel surveyInfoModel = form.SurveyInfo.ToFormInfoModel(); MetadataAccessor metadataAccessor = form.SurveyInfo as MetadataAccessor; // set the survey answer to be production or test surveyAnswer.IsDraftMode = form.SurveyInfo.IsDraftMode; TempData[TempDataKeys.Width] = form.Width + 100; string checkcode = MetadataAccessor.GetFormDigest(surveyId).CheckCode; form.FormCheckCodeObj = form.GetCheckCodeObj(metadataAccessor.GetFieldDigests(surveyId), surveyAnswer.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(); var responseDetail = surveyAnswer.ResponseDetail; 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 = Epi.Cloud.MVC.Utility.SurveyHelper.GetContextDetailList(functionObject_B); form = Epi.Cloud.MVC.Utility.SurveyHelper.UpdateControlsValuesFromContext(form, contextDetailList); _surveyFacade.UpdateSurveyResponse(surveyInfoModel, responseId.ToString(), form, surveyAnswer, false, false, 0, orgId, userId, userName); } catch (Exception ex) { // do nothing so that processing // can continue } } else { PageDigest[] pageDigestArray = metadataAccessor.GetPageDigests(surveyInfoModel.SurveyId); surveyAnswer.ResponseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigestArray); _requiredList = surveyResponseBuilder.RequiredList; SetSessionValue(UserSession.Key.RequiredList, surveyResponseBuilder.RequiredList); form.RequiredFieldsList = _requiredList; } ///////////////////////////// Execute - Record Before - End////////////////////// return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = responseId, PageNumber = 1, surveyid = surveyInfoModel.SurveyId })); }
public ActionResult Index(Epi.Web.MVC.Models.SurveyInfoModel surveyModel) { try { bool IsMobileDevice = this.Request.Browser.IsMobileDevice; if (IsMobileDevice == false) { IsMobileDevice = Epi.Web.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString()); } FormsAuthentication.SetAuthCookie("BeginSurvey", false); Session["RootResponseId"] = surveyModel.ResponseId; string ResponseID = surveyModel.ResponseId; //string.Empty; //object tempDataValue; //if (TempData.TryGetValue(Epi.Web.MVC.Constants.Constant.RESPONSE_ID, out tempDataValue)) //{ // ResponseID = (string)tempDataValue; //} //else //{ //} Epi.Web.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(surveyModel.SurveyId, ResponseID.ToString()); Epi.Web.Common.Message.UserAuthenticationResponse AuthenticationResponse = _isurveyFacade.GetAuthenticationResponse(ResponseID.ToString()); string strPassCode = Epi.Web.MVC.Utility.SurveyHelper.GetPassCode(); if (string.IsNullOrEmpty(AuthenticationResponse.PassCode)) { //_isurveyFacade.UpdatePassCode(ResponseID.ToString(), TempData["PassCode"].ToString()); _isurveyFacade.UpdatePassCode(ResponseID.ToString(), surveyModel.PassCode); } Epi.Web.Common.Message.SurveyAnswerResponse SurveyAnswerResponse = _isurveyFacade.GetSurveyAnswerResponse(ResponseID); SurveyAnswer = SurveyAnswerResponse.SurveyResponseList[0]; SurveyInfoModel surveyInfoModel = GetSurveyInfo(SurveyAnswer.SurveyId); // set the survey answer to be production or test SurveyAnswer.IsDraftMode = surveyInfoModel.IsDraftMode; XDocument xdoc = XDocument.Parse(surveyInfoModel.XML); // MvcDynamicForms.Form form = _isurveyFacade.GetSurveyFormData(SurveyAnswer.SurveyId, 1, SurveyAnswer, IsMobileDevice, "homeController"); MvcDynamicForms.Form form = _isurveyFacade.GetSurveyFormData(SurveyAnswer.SurveyId, 1, SurveyAnswer, IsMobileDevice, null); var _FieldsTypeIDs = from _FieldTypeID in xdoc.Descendants("Field") select _FieldTypeID; TempData["Width"] = form.Width + 100; XDocument xdocResponse = XDocument.Parse(SurveyAnswer.XML); XElement ViewElement = xdoc.XPathSelectElement("Template/Project/View"); string checkcode = ViewElement.Attribute("CheckCode").Value.ToString(); form.FormCheckCodeObj = form.GetCheckCodeObj(xdoc, xdocResponse, 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="); if (FunctionObject_B != null && !FunctionObject_B.IsNull()) { try { SurveyAnswer.XML = CreateResponseDocument(xdoc, SurveyAnswer.XML); form.RequiredFieldsList = this.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 = Epi.Web.MVC.Utility.SurveyHelper.GetContextDetailList(FunctionObject_B); form = Epi.Web.MVC.Utility.SurveyHelper.UpdateControlsValuesFromContext(form, ContextDetailList); SurveyAnswer.RecordBeforeFlag = true; _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, ResponseID.ToString(), form, SurveyAnswer, false, false, 0); } catch (Exception ex) { // do nothing so that processing // can continue } } else { SurveyAnswer.XML = CreateResponseDocument(xdoc, SurveyAnswer.XML); form.RequiredFieldsList = RequiredList; _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, SurveyAnswer.ResponseId, form, SurveyAnswer, false, false, 0); } SurveyAnswer = _isurveyFacade.GetSurveyAnswerResponse(SurveyAnswer.ResponseId).SurveyResponseList[0]; ///////////////////////////// Execute - Record Before - End////////////////////// //string page; // return RedirectToAction(Epi.Web.Models.Constants.Constant.INDEX, Epi.Web.Models.Constants.Constant.SURVEY_CONTROLLER, new {id="page" }); return(RedirectToAction(Epi.Web.MVC.Constants.Constant.INDEX, Epi.Web.MVC.Constants.Constant.SURVEY_CONTROLLER, new { responseid = ResponseID, PageNumber = 1 })); } catch (Exception ex) { Epi.Web.Utility.ExceptionMessage.SendLogMessage(ex, this.HttpContext); return(View(Epi.Web.MVC.Constants.Constant.EXCEPTION_PAGE)); } }
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 })); }