public ActionResult Index(string surveyid, string AddNewFormId, string EditForm)
        {
            int  UserId       = SurveyHelper.GetDecryptUserId(Session["UserId"].ToString());
            int  CuurentOrgId = int.Parse(Session["SelectedOrgId"].ToString());
            Guid ResponseID   = Guid.NewGuid();

            Session["FormValuesHasChanged"] = "";

            TempData[Epi.Web.MVC.Constants.Constant.RESPONSE_ID] = Session["RootResponseId"] = ResponseID.ToString();


            if (string.IsNullOrEmpty(EditForm) && Session["EditForm"] != null)
            {
                EditForm = Session["EditForm"].ToString();
            }

            if (!string.IsNullOrEmpty(EditForm) && string.IsNullOrEmpty(AddNewFormId))
            {
                Session["RootResponseId"] = EditForm.ToLower();

                Session["IsEditMode"] = true;
                Epi.Web.Enter.Common.DTO.SurveyAnswerDTO surveyAnswerDTO = GetSurveyAnswer(EditForm, Session["RootFormId"].ToString());


                Session["RequestedViewId"] = surveyAnswerDTO.ViewId;
                if (Session["RecoverLastRecordVersion"] != null)
                {
                    surveyAnswerDTO.RecoverLastRecordVersion = bool.Parse(Session["RecoverLastRecordVersion"].ToString());
                }
                string ChildRecordId = GetChildRecordId(surveyAnswerDTO);
                Session["RecoverLastRecordVersion"] = false;
                return(RedirectToAction(Epi.Web.MVC.Constants.Constant.INDEX, Epi.Web.MVC.Constants.Constant.SURVEY_CONTROLLER, new { responseid = ChildRecordId, PageNumber = 1, Edit = "Edit" }));
            }
            else
            {
                Session["IsEditMode"] = false;
            }
            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["RootFormId"] = AddNewFormId;
            //create the responseid
            Epi.Web.Enter.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(AddNewFormId, ResponseID.ToString(), UserId, false, "", false, CuurentOrgId);
            MvcDynamicForms.Form form = _isurveyFacade.GetSurveyFormData(SurveyAnswer.SurveyId, 1, SurveyAnswer, IsMobileDevice, null, null, false, false);
            TempData["Width"] = form.Width + 100;
            SurveyInfoModel surveyInfoModel = Mapper.ToFormInfoModel(form.SurveyInfo);

            // set the survey answer to be production or test
            SurveyAnswer.IsDraftMode = form.SurveyInfo.IsDraftMode;
            XDocument xdoc = XDocument.Parse(form.SurveyInfo.XML);

            ///////////////////////////// Execute - Record Before - start//////////////////////
            Dictionary <string, string> ContextDetailList = new Dictionary <string, string>();
            EnterRule         FunctionObject_B            = (EnterRule)form.FormCheckCodeObj.GetCommand("level=record&event=before&identifier=");
            SurveyResponseXML SurveyResponseXML           = new SurveyResponseXML(PageFields, RequiredList);

            if (FunctionObject_B != null && !FunctionObject_B.IsNull())
            {
                try
                {
                    SurveyAnswer.XML        = SurveyResponseXML.CreateResponseDocument(xdoc, SurveyAnswer.XML);
                    Session["RequiredList"] = SurveyResponseXML._RequiredList;
                    //SurveyAnswer.XML = Epi.Web.MVC.Utility.SurveyHelper.CreateResponseDocument(xdoc, SurveyAnswer.XML, RequiredList);
                    this.RequiredList       = SurveyResponseXML._RequiredList;
                    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);

                    _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, ResponseID.ToString(), form, SurveyAnswer, false, false, 0, SurveyHelper.GetDecryptUserId(Session["UserId"].ToString()));
                }
                catch (Exception ex)
                {
                    // do nothing so that processing
                    // can continue
                }
            }
            else
            {
                SurveyAnswer.XML        = SurveyResponseXML.CreateResponseDocument(xdoc, SurveyAnswer.XML);//, RequiredList);
                this.RequiredList       = SurveyResponseXML._RequiredList;
                Session["RequiredList"] = SurveyResponseXML._RequiredList;
                form.RequiredFieldsList = RequiredList;
                _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, SurveyAnswer.ResponseId, form, SurveyAnswer, false, false, 0, SurveyHelper.GetDecryptUserId(Session["UserId"].ToString()));
            }


            return(RedirectToAction(Epi.Web.MVC.Constants.Constant.INDEX, Epi.Web.MVC.Constants.Constant.SURVEY_CONTROLLER, new { responseid = ResponseID, PageNumber = 1, surveyid = surveyInfoModel.SurveyId }));
        }
Ejemplo n.º 2
0
        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));
            }
        }