Beispiel #1
0
        /// <summary>
        /// Creates the first survey response in the response table
        /// </summary>
        /// <param name="surveyId"></param>
        /// <param name="responseId"></param>
        /// <param name="surveyAnswerRequest"></param>
        /// <param name="surveyAnswerDTO"></param>
        /// <param name="surveyResponseXML"></param>
        /// <param name="iSurveyAnswerRepository"></param>
        public static Epi.Web.Common.DTO.SurveyAnswerDTO CreateSurveyResponse(string surveyId, string responseId, SurveyAnswerRequest surveyAnswerRequest1,
                                                                              Common.DTO.SurveyAnswerDTO surveyAnswerDTO,
                                                                              SurveyResponseXML surveyResponseXML, ISurveyAnswerRepository iSurveyAnswerRepository, int UserId, bool IsChild = false, string RelateResponseId = "", bool IsEditMode = false, int CurrentOrgId = -1)
        {
            bool AddRoot = false;
            SurveyAnswerRequest surveyAnswerRequest = new SurveyAnswerRequest();

            surveyAnswerRequest.Criteria.SurveyAnswerIdList.Add(responseId.ToString());
            surveyAnswerDTO.ResponseId = responseId.ToString();
            //surveyAnswerDTO.DateCompleted = DateTime.Now;
            surveyAnswerDTO.DateCreated    = DateTime.Now;
            surveyAnswerDTO.SurveyId       = surveyId;
            surveyAnswerDTO.Status         = (int)Constant.Status.InProgress;
            surveyAnswerDTO.RecordSourceId = 4;
            if (IsEditMode)
            {
                surveyAnswerDTO.ParentRecordId = RelateResponseId;
            }
            //if (IsEditMode)
            //    {
            //    surveyAnswerDTO.Status = (int)Constant.Status.Complete;
            //    }
            //else
            //    {
            //    surveyAnswerDTO.Status = (int)Constant.Status.InProgress;
            //    }
            surveyAnswerDTO.XML                             = surveyResponseXML.CreateResponseXml(surveyId, AddRoot, 0, "0").InnerXml;
            surveyAnswerDTO.RelateParentId                  = RelateResponseId;
            surveyAnswerRequest.Criteria.UserId             = UserId;
            surveyAnswerRequest.Criteria.UserOrganizationId = CurrentOrgId;
            surveyAnswerRequest.SurveyAnswerList.Add(surveyAnswerDTO);
            if (!IsChild)
            {
                surveyAnswerRequest.Action = Epi.Web.MVC.Constants.Constant.CREATE;
            }
            else
            {
                if (IsEditMode)
                {
                    surveyAnswerRequest.SurveyAnswerList[0].ParentRecordId = null;
                }

                surveyAnswerRequest.Action = Epi.Web.MVC.Constants.Constant.CREATECHILD;
            }

            iSurveyAnswerRepository.SaveSurveyAnswer(surveyAnswerRequest);

            return(surveyAnswerDTO);
        }
Beispiel #2
0
        public static void UpdateSurveyResponse(SurveyInfoModel surveyInfoModel, MvcDynamicForms.Form form, SurveyAnswerRequest surveyAnswerRequest,
                                                SurveyResponseXML surveyResponseXML,
                                                ISurveyAnswerRepository iSurveyAnswerRepository,
                                                SurveyAnswerResponse surveyAnswerResponse, string responseId, Epi.Web.Common.DTO.SurveyAnswerDTO surveyAnswerDTO, bool IsSubmited, bool IsSaved, int PageNumber, int UserId = -1)
        {
            // 1 Get the record for the current survey response
            // 2 update the current survey response
            // 3 save the current survey response
            if (!IsSubmited)
            {
                // 2 a. update the current survey answer request
                surveyAnswerRequest.SurveyAnswerList = surveyAnswerResponse.SurveyResponseList;

                surveyResponseXML.Add(form);
                XDocument SavedXml = XDocument.Parse(surveyAnswerDTO.XML);
                bool      AddRoot  = false;
                if (SavedXml.Root.FirstAttribute.Value.ToString() == "0")
                {
                    AddRoot = true;
                }
                surveyAnswerRequest.SurveyAnswerList[0].XML = surveyResponseXML.CreateResponseXml(surveyInfoModel.SurveyId, AddRoot, form.CurrentPage, form.PageId).InnerXml;
                // 2 b. save the current survey response
                surveyAnswerRequest.Action = Epi.Web.MVC.Constants.Constant.UPDATE;  //"Update";
                //Append to Response Xml

                XDocument CurrentPageResponseXml = XDocument.Parse(surveyAnswerRequest.SurveyAnswerList[0].XML);
                if (SavedXml.Root.FirstAttribute.Value.ToString() != "0")
                {
                    surveyAnswerRequest.SurveyAnswerList[0].XML = MergeXml(SavedXml, CurrentPageResponseXml, form.CurrentPage).ToString();
                }
            }
            ////Update page number before saving response XML

            XDocument Xdoc = XDocument.Parse(surveyAnswerRequest.SurveyAnswerList[0].XML);

            if (PageNumber != 0)
            {
                Xdoc.Root.Attribute("LastPageVisited").Value = PageNumber.ToString();
            }
            ////Update Hidden Fields List before saving response XML
            if (form.HiddenFieldsList != null)
            {
                Xdoc.Root.Attribute("HiddenFieldsList").Value = "";
                Xdoc.Root.Attribute("HiddenFieldsList").Value = form.HiddenFieldsList.ToString();
            }
            if (form.HighlightedFieldsList != null)
            {
                Xdoc.Root.Attribute("HighlightedFieldsList").Value = "";
                Xdoc.Root.Attribute("HighlightedFieldsList").Value = form.HighlightedFieldsList.ToString();
            }
            if (form.DisabledFieldsList != null)
            {
                Xdoc.Root.Attribute("DisabledFieldsList").Value = "";
                Xdoc.Root.Attribute("DisabledFieldsList").Value = form.DisabledFieldsList.ToString();
            }
            if (form.RequiredFieldsList != null)
            {
                Xdoc.Root.Attribute("RequiredFieldsList").Value = "";
                Xdoc.Root.Attribute("RequiredFieldsList").Value = form.RequiredFieldsList.ToString();
            }
            if (surveyAnswerDTO.RecordBeforeFlag)
            {
                Xdoc.Root.Attribute("RecordBeforeFlag").Value = "True";
            }
            //  AssignList
            List <KeyValuePair <string, String> > FieldsList = new List <KeyValuePair <string, string> >();

            FieldsList = GetHiddenFieldsList(form);
            if (FieldsList != null)
            {
                IEnumerable <XElement> XElementList = Xdoc.XPathSelectElements("SurveyResponse/Page/ResponseDetail");
                for (var i = 0; i < FieldsList.Count; i++)
                {
                    foreach (XElement Element in XElementList)
                    {
                        if (Element.Attribute("QuestionName").Value.ToString().Equals(FieldsList[i].Key, StringComparison.OrdinalIgnoreCase))
                        {
                            if (FieldsList[i].Value != null)
                            {
                                Element.Value = FieldsList[i].Value;
                            }
                            break;
                        }
                    }
                }
            }



            ////Update survey response Status
            if (IsSubmited)
            {
                surveyAnswerRequest.SurveyAnswerList[0].Status        = 3;
                surveyAnswerRequest.SurveyAnswerList[0].DateCompleted = DateTime.Now;
                surveyAnswerRequest.SurveyAnswerList[0].Json          = surveyAnswerResponse.SurveyResponseList[0].Json;
                // Xdoc.Root.Attribute("LastPageVisited").Remove();
                // Xdoc.Root.Attribute("HiddenFieldsList").Remove();
                // Xdoc.Root.Attribute("HighlightedFieldsList").Remove();
                //Xdoc.Root.Attribute("DisabledFieldsList").Remove();
                //Xdoc.Root.Attribute("RequiredFieldsList").Remove();
                //   Xdoc.Root.Attribute("RecordBeforeFlag").Remove();
                //RemovePageNumAtt(Xdoc);
            }
            if (IsSaved)
            {
                surveyAnswerRequest.SurveyAnswerList[0].Status = 2;
            }
            surveyAnswerRequest.SurveyAnswerList[0].XML = Xdoc.ToString();
            /////Update Survey Mode ////////////////////
            surveyAnswerRequest.SurveyAnswerList[0].IsDraftMode = surveyAnswerDTO.IsDraftMode;
            iSurveyAnswerRepository.SaveSurveyAnswer(surveyAnswerRequest);
        }