Exemplo n.º 1
0
        public ActionResult Index(string surveyId, SurveyAnswerModel surveyAnswerModel)
        {
            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);
                Guid responseId = Guid.NewGuid();
                Epi.Web.Enter.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(surveyId, responseId.ToString(), 0);
                SurveyInfoModel      surveyInfoModel = GetSurveyInfo(SurveyAnswer.SurveyId);
                XDocument            xdoc            = XDocument.Parse(surveyInfoModel.XML);
                MvcDynamicForms.Form form            = _isurveyFacade.GetSurveyFormData(SurveyAnswer.SurveyId, 1, SurveyAnswer, IsMobileDevice);

                var _FieldsTypeIDs = from _FieldTypeID in
                                     xdoc.Descendants("Field")
                                     select _FieldTypeID;

                foreach (var _FieldTypeID in _FieldsTypeIDs)
                {
                    bool   isRequired;
                    string attributeValue = _FieldTypeID.Attribute("IsRequired").Value;

                    if (bool.TryParse(attributeValue, out isRequired))
                    {
                        if (isRequired)
                        {
                            if (!form.RequiredFieldsList.Contains(_FieldTypeID.Attribute("Name").Value))
                            {
                                if (form.RequiredFieldsList != "")
                                {
                                    form.RequiredFieldsList = form.RequiredFieldsList + "," + _FieldTypeID.Attribute("Name").Value.ToLower();
                                }
                                else
                                {
                                    form.RequiredFieldsList = _FieldTypeID.Attribute("Name").Value.ToLower();
                                }
                            }
                        }
                    }
                }

                _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, SurveyAnswer.ResponseId, form, SurveyAnswer, false, false, 1, 0);

                return(RedirectToRoute(new { Controller = "Survey", Action = "Index", 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, SurveyAnswerModel surveyAnswerModel)
        {
            try
            {
                bool isMobileDevice = this.Request.Browser.IsMobileDevice;

                if (isMobileDevice == false)
                {
                    isMobileDevice = Epi.Cloud.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString());
                }

                FormsAuthentication.SetAuthCookie("BeginSurvey", false);

                Guid responseId = Guid.NewGuid();

                var             responseContext = InitializeResponseContext(formId: surveyId, responseId: responseId.ToString());
                SurveyAnswerDTO surveyAnswer    = _isurveyFacade.CreateSurveyAnswer(responseContext);
                SurveyInfoModel surveyInfoModel = GetSurveyInfo(surveyId);

                MvcDynamicForms.Form form = _isurveyFacade.GetSurveyFormData(surveyId, 1, surveyAnswer, isMobileDevice);

                List <string> requiredFields = null;

                foreach (var field in surveyInfoModel.GetFieldDigests(surveyId))
                {
                    bool isRequired = field.IsRequired;

                    if (isRequired)
                    {
                        // if this is the first new required field then split the existing required CSV into a true list.
                        requiredFields = requiredFields ?? new List <string>(form.RequiredFieldsList.Split(','));

                        if (!requiredFields.Contains(field.FieldName))
                        {
                            requiredFields.Add(field.FieldName.ToLower());
                        }
                    }
                }

                // if we processed at least 1 reqired field then join the required field list into a CSV list
                if (requiredFields != null)
                {
                    form.RequiredFieldsList = string.Join(",", requiredFields);
                }

                _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, surveyAnswer.ResponseId, form, surveyAnswer, false, false, 1, responseContext.UserOrgId, responseContext.UserId, null);

                return(RedirectToRoute(new { Controller = "Survey", Action = "Index", responseId = responseId, PageNumber = 1 }));
            }
            catch (Exception ex)
            {
                Epi.Web.Utility.ExceptionMessage.SendLogMessage(ex, this.HttpContext);
                return(View(ViewActions.Exception));
            }
        }
        public ActionResult Index(string surveyId, SurveyAnswerModel surveyAnswerModel)
        {
            try
            {
                bool isMobileDevice = this.Request.Browser.IsMobileDevice;

                if (isMobileDevice == false)
                {
                    isMobileDevice = Epi.Web.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString());
                }
                if (!string.IsNullOrEmpty(this.Request.Form["is_print_action"]) && this.Request.Form["is_print_action"].ToString().Equals("true", StringComparison.OrdinalIgnoreCase))
                {
                    string       ResponseId   = this.Request.Form["ResponseId"];
                    ActionResult actionResult = RedirectToAction("Index", "Print", new { responseId = ResponseId, FromFinal = true });
                    return(actionResult);
                }
                //FormsAuthentication.SignOut();
                FormsAuthentication.SetAuthCookie("BeginSurvey", false);
                Guid responseId = Guid.NewGuid();
                Epi.Web.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(surveyId, responseId.ToString());

                // Pass Code Logic  start
                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());
                }


                SurveyInfoModel      surveyInfoModel = GetSurveyInfo(SurveyAnswer.SurveyId);
                XDocument            xdoc            = XDocument.Parse(surveyInfoModel.XML);
                MvcDynamicForms.Form form            = _isurveyFacade.GetSurveyFormData(SurveyAnswer.SurveyId, 1, SurveyAnswer, isMobileDevice);

                var _FieldsTypeIDs = from _FieldTypeID in
                                     xdoc.Descendants("Field")
                                     select _FieldTypeID;

                foreach (var _FieldTypeID in _FieldsTypeIDs)
                {
                    bool   isRequired;
                    string attributeValue = _FieldTypeID.Attribute("IsRequired").Value;

                    if (bool.TryParse(attributeValue, out isRequired))
                    {
                        if (isRequired)
                        {
                            if (!form.RequiredFieldsList.Contains(_FieldTypeID.Attribute("Name").Value))
                            {
                                if (form.RequiredFieldsList != "")
                                {
                                    form.RequiredFieldsList = form.RequiredFieldsList + "," + _FieldTypeID.Attribute("Name").Value.ToLower();
                                }
                                else
                                {
                                    form.RequiredFieldsList = _FieldTypeID.Attribute("Name").Value.ToLower();
                                }
                            }
                        }
                    }
                }
                SurveyAnswer.XML = CreateResponseDocument(xdoc, SurveyAnswer.XML);
                _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, SurveyAnswer.ResponseId, form, SurveyAnswer, false, false, 1);

                return(RedirectToRoute(new { Controller = "Survey", Action = "Index", responseId = responseId, PageNumber = 1 }));
            }
            catch (Exception ex)
            {
                Epi.Web.Utility.ExceptionMessage.SendLogMessage(ex, this.HttpContext);
                return(View(Epi.Web.MVC.Constants.Constant.EXCEPTION_PAGE));
            }
        }