/// <summary>
        /// Inserts SurveyResponse
        /// </summary>
        /// <param name="SurveyResponseApiModel"></param>
        /// <returns>response </returns>
        public PreFilledAnswerResponse SetSurveyAnswer(SurveyResponseApiModel request)
        {
            PreFilledAnswerResponse response;
            SurveyControlsResponse  SurveyControlsResponse = new SurveyControlsResponse();
            SurveyControlsRequest   surveyControlsRequest  = new SurveyControlsRequest();

            surveyControlsRequest.SurveyId = request.SurveyId.ToString();
            try
            {
                Interfaces.DataInterfaces.ISurveyResponseDao     SurveyResponseDao = new EntitySurveyResponseDao();
                Epi.Web.Interfaces.DataInterfaces.ISurveyInfoDao ISurveyInfoDao    = new EntitySurveyInfoDao();
                BLL.SurveyResponse          Implementation         = new BLL.SurveyResponse(SurveyResponseDao, ISurveyInfoDao);
                PreFilledAnswerRequest      prefilledanswerRequest = new PreFilledAnswerRequest();
                Dictionary <string, string> Values = new Dictionary <string, string>();
                prefilledanswerRequest.AnswerInfo.UserPublishKey  = request.PublisherKey;
                prefilledanswerRequest.AnswerInfo.OrganizationKey = request.OrgKey;
                prefilledanswerRequest.AnswerInfo.SurveyId        = request.SurveyId;
                prefilledanswerRequest.AnswerInfo.UserPublishKey  = request.PublisherKey;
                List <SurveyInfoBO> SurveyBOList = GetSurveyInfo(prefilledanswerRequest);
                GetRootFormId(prefilledanswerRequest);
                prefilledanswerRequest.AnswerInfo.SurveyId = request.SurveyId;
                SurveyControlsResponse = GetSurveyControlsList(surveyControlsRequest);
                Dictionary <string, string> FilteredAnswerList = new Dictionary <string, string>();
                var radiolist = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "GroupBoxRadioList");
                FilteredAnswerList = ProcessModforRadioControls(radiolist, request.SurveyQuestionAnswerListField);
                var checkboxLsit = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "CheckBox");
                FilteredAnswerList = ProcessValforCheckBoxControls(checkboxLsit, FilteredAnswerList);
                var yesNoList = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "YesNo");
                FilteredAnswerList = ProcessValforYesNoControls(yesNoList, FilteredAnswerList);
                var legalvalList = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "LegalValues");
                FilteredAnswerList = ProcessValforLegalControls(legalvalList, FilteredAnswerList);
                foreach (KeyValuePair <string, string> entry in FilteredAnswerList)
                {
                    Values.Add(entry.Key, entry.Value);
                }
                prefilledanswerRequest.AnswerInfo.SurveyQuestionAnswerList = Values;
                response = Implementation.SetSurveyAnswer(prefilledanswerRequest);
                return(response);
            }
            catch (Exception ex)
            {
                PassCodeDTO DTOList = new PassCodeDTO();
                response = new PreFilledAnswerResponse(DTOList);
                if (response.ErrorMessageList != null)
                {
                    response.ErrorMessageList.Add("Failed", "Failed to insert Response");
                }
                response.Status = ((BLL.SurveyResponse.Message) 1).ToString();
                return(response);
            }
        }
        public PreFilledAnswerResponse SetSurveyAnswer(PreFilledAnswerRequest request)
        {
            string SurveyId       = request.AnswerInfo.SurveyId.ToString();
            string ResponseId     = request.AnswerInfo.ResponseId.ToString();
            Guid   ParentRecordId = request.AnswerInfo.ParentRecordId;
            Dictionary <string, string> ErrorMessageList = new Dictionary <string, string>();
            PreFilledAnswerResponse     response;


            SurveyResponseBO            SurveyResponse = new SurveyResponseBO();
            UserAuthenticationRequestBO UserAuthenticationRequestBO = new UserAuthenticationRequestBO();
            //Get Survey Info (MetaData)
            List <SurveyInfoBO> SurveyBOList = GetSurveyInfo(request);
            //Build Survey Response Xml

            string Xml = CreateResponseXml(request, SurveyBOList);

            //Validate Response values

            ErrorMessageList = ValidateResponse(SurveyBOList, request);

            if (ErrorMessageList.Count() > 0)
            {
                response = new PreFilledAnswerResponse();
                response.ErrorMessageList = ErrorMessageList;
                response.Status           = ((Message)1).ToString();
            }
            else
            {
                //Insert Survey Response
                SurveyResponse = this.SurveyResponseDao.GetSingleResponse(request.AnswerInfo.ResponseId.ToString());
                if (SurveyResponse.SurveyId == null)
                {
                    SurveyResponse  = InsertSurveyResponse(Mapper.ToBusinessObject(Xml, request.AnswerInfo.SurveyId.ToString(), request.AnswerInfo.ParentRecordId.ToString(), request.AnswerInfo.ResponseId.ToString(), request.AnswerInfo.UserId));
                    response        = new PreFilledAnswerResponse();
                    response.Status = ((Message)2).ToString();
                }
                else
                {
                    UpdateFormResponse(Mapper.ToBusinessObject(Xml, request.AnswerInfo.SurveyId.ToString(), request.AnswerInfo.ParentRecordId.ToString(), request.AnswerInfo.ResponseId.ToString(), request.AnswerInfo.UserId));
                    response        = new PreFilledAnswerResponse();
                    response.Status = ((Message)2).ToString();
                }
            }


            return(response);
        }
        public PreFilledAnswerResponse SetSurveyAnswer(PreFilledAnswerRequest request)
        {
            try
            {
                PreFilledAnswerResponse response;
                Epi.Web.Enter.Interfaces.DataInterfaces.ISurveyResponseDao SurveyResponseDao = new EF.EntitySurveyResponseDao();
                Epi.Web.BLL.SurveyResponse Implementation = new Epi.Web.BLL.SurveyResponse(SurveyResponseDao);

                response = Implementation.SetSurveyAnswer(request);

                return(response);
            }
            catch (Exception ex)
            {
                // PassCodeDTO DTOList = new Common.DTO.PassCodeDTO();
                // PreFilledAnswerResponse response = new PreFilledAnswerResponse(DTOList);
                PreFilledAnswerResponse response = new PreFilledAnswerResponse();
                response.ErrorMessageList.Add("Failed", "Failed to insert Response");
                response.Status = ((Epi.Web.BLL.SurveyResponse.Message) 1).ToString();
                return(response);
            }
        }
        /// <summary>
        /// Updates SurveyResponse
        /// </summary>
        /// <param name="SurveyResponseApiModel",name="ResponseId"></param>
        /// <returns>response </returns>
        public PreFilledAnswerResponse Update(SurveyResponseApiModel request, string ResponseId)
        {
            PreFilledAnswerResponse response;
            SurveyControlsResponse  SurveyControlsResponse = new SurveyControlsResponse();
            SurveyControlsRequest   surveyControlsRequest  = new SurveyControlsRequest();

            surveyControlsRequest.SurveyId = request.SurveyId.ToString();

            try
            {
                Interfaces.DataInterfaces.ISurveyResponseDao SurveyResponseDao = new EntitySurveyResponseDao();
                Interfaces.DataInterfaces.ISurveyInfoDao     ISurveyInfoDao    = new EntitySurveyInfoDao();
                BLL.SurveyResponse          Implementation         = new BLL.SurveyResponse(SurveyResponseDao, ISurveyInfoDao);
                PreFilledAnswerRequest      prefilledanswerRequest = new PreFilledAnswerRequest();
                Dictionary <string, string> Values = new Dictionary <string, string>();
                prefilledanswerRequest.AnswerInfo.UserPublishKey  = request.PublisherKey;
                prefilledanswerRequest.AnswerInfo.OrganizationKey = request.OrgKey;
                prefilledanswerRequest.AnswerInfo.SurveyId        = request.SurveyId;
                prefilledanswerRequest.AnswerInfo.UserPublishKey  = request.PublisherKey;
                List <SurveyInfoBO> SurveyBOList = GetSurveyInfo(prefilledanswerRequest);
                GetRootFormId(prefilledanswerRequest);
                prefilledanswerRequest.AnswerInfo.SurveyId = request.SurveyId;
                SurveyControlsResponse = GetSurveyControlsList(surveyControlsRequest);
                Dictionary <string, string> FilteredAnswerList = new Dictionary <string, string>();
                var radiolist = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "GroupBoxRadioList");
                FilteredAnswerList = ProcessModforRadioControls(radiolist, request.SurveyQuestionAnswerListField);
                var checkboxLsit = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "CheckBox");
                FilteredAnswerList = ProcessValforCheckBoxControls(checkboxLsit, FilteredAnswerList);
                var yesNoList = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "YesNo");
                FilteredAnswerList = ProcessValforYesNoControls(yesNoList, FilteredAnswerList);
                var legalvalList = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "LegalValues");
                FilteredAnswerList = ProcessValforLegalControls(legalvalList, FilteredAnswerList);

                var updatedtime = FilteredAnswerList.Where(x => x.Key.ToLower() == "_updatestamp").FirstOrDefault();
                var Responsekey = FilteredAnswerList.Where(x => x.Key.ToLower() == "responseid" || x.Key.ToLower() == "id").FirstOrDefault().Key;
                var fkey        = FilteredAnswerList.Where(x => x.Key.ToLower() == "fkey").FirstOrDefault();
                foreach (KeyValuePair <string, string> entry in FilteredAnswerList)
                {
                    Values.Add(entry.Key, entry.Value);
                }

                try
                {
                    var survey = Implementation.GetSurveyResponseById(new List <string> {
                        ResponseId
                    }, request.PublisherKey);
                }
                catch (Exception ex)
                {
                    prefilledanswerRequest.AnswerInfo.SurveyQuestionAnswerList = Values;
                    response        = Implementation.SetSurveyAnswer(prefilledanswerRequest);
                    response.Status = "Created";
                    return(response);
                }


                Values.Remove(Responsekey);
                if (updatedtime.Key != null)
                {
                    Values.Remove(updatedtime.Key);
                }
                if (fkey.Key != null)
                {
                    Values.Remove(fkey.Key);
                }

                prefilledanswerRequest.AnswerInfo.SurveyQuestionAnswerList = Values;

                Dictionary <string, string> ErrorMessageList = new Dictionary <string, string>();

                string Xml = Implementation.CreateResponseXml(prefilledanswerRequest, SurveyBOList);      //
                ErrorMessageList = Implementation.ValidateResponse(SurveyBOList, prefilledanswerRequest); //
                if (fkey.Key != null)
                {
                    try
                    {
                        var survey = Implementation.GetSurveyResponseById(new List <string> {
                            fkey.Value
                        }, request.PublisherKey);
                    }
                    catch (Exception ex)
                    {
                        SurveyResponseBO surveyresponsebO = new SurveyResponseBO();
                        surveyresponsebO.SurveyId       = SurveyBOList[0].ParentId;
                        surveyresponsebO.ResponseId     = fkey.Value.ToString();
                        surveyresponsebO.XML            = "  ";
                        surveyresponsebO.Status         = 3;
                        surveyresponsebO.RecrodSourceId = (int)ValidationRecordSourceId.MA;
                        surveyresponsebO.DateUpdated    = DateTime.Now;
                        surveyresponsebO.DateCreated    = surveyresponsebO.DateUpdated;
                        surveyresponsebO.DateCompleted  = surveyresponsebO.DateUpdated;
                        surveyresponsebO = Implementation.InsertSurveyResponseApi(surveyresponsebO);
                    }
                }

                if (ErrorMessageList.Count() > 0)
                {
                    response = new PreFilledAnswerResponse();
                    response.ErrorMessageList = ErrorMessageList;
                    response.ErrorMessageList.Add("SurveyId", request.SurveyId.ToString());
                    response.ErrorMessageList.Add("ResponseId", ResponseId);
                    response.Status = ((Epi.Web.BLL.SurveyResponse.Message) 1).ToString();
                    Implementation.InsertErrorLog(response.ErrorMessageList);
                }
                SurveyResponseBO            surveyresponseBO = new SurveyResponseBO(); SurveyResponseBO SurveyResponse = new SurveyResponseBO();
                UserAuthenticationRequestBO UserAuthenticationRequestBO = new UserAuthenticationRequestBO();
                surveyresponseBO.SurveyId   = request.SurveyId.ToString();
                surveyresponseBO.ResponseId = ResponseId.ToString();
                surveyresponseBO.XML        = Xml;
                System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                if (updatedtime.Key != null)
                {
                    surveyresponseBO.DateUpdated   = dateTime.AddMilliseconds(Convert.ToDouble(updatedtime.Value.ToString())).ToLocalTime();
                    surveyresponseBO.DateCompleted = dateTime.AddMilliseconds(Convert.ToDouble(updatedtime.Value.ToString())).ToLocalTime();
                }
                else
                {
                    surveyresponseBO.DateUpdated   = DateTime.Now;
                    surveyresponseBO.DateCompleted = DateTime.Now;
                }
                if (fkey.Key != null)
                {
                    surveyresponseBO.RelateParentId = fkey.Value;
                }
                surveyresponseBO.Status     = 3;
                SurveyResponse              = Implementation.UpdateSurveyResponse(surveyresponseBO);
                UserAuthenticationRequestBO = Web.Common.ObjectMapping.Mapper.ToBusinessObject(ResponseId);
                Implementation.SavePassCode(UserAuthenticationRequestBO);

                //return Response
                string ResponseUrl = ConfigurationManager.AppSettings["ResponseURL"];
                response = new PreFilledAnswerResponse(Web.Common.ObjectMapping.Mapper.ToDataTransferObjects(UserAuthenticationRequestBO));
                response.SurveyResponseUrl = ResponseUrl + UserAuthenticationRequestBO.ResponseId;
                response.Status            = ((Epi.Web.BLL.SurveyResponse.Message) 2).ToString();
                return(response);
            }
            catch (Exception ex)
            {
                PassCodeDTO DTOList = new PassCodeDTO();
                response = new PreFilledAnswerResponse(DTOList);
                if (response.ErrorMessageList != null)
                {
                    response.ErrorMessageList.Add("Failed", "Failed to insert Response");
                }
                response.Status = ((BLL.SurveyResponse.Message) 1).ToString();
                return(response);
            }
        }
Example #5
0
        public PreFilledAnswerResponse SetSurveyAnswer(PreFilledAnswerRequest request)
        {
            string SurveyId       = request.AnswerInfo.SurveyId.ToString();
            string OrganizationId = request.AnswerInfo.OrganizationKey.ToString();
            Guid   UserPublishKey = request.AnswerInfo.UserPublishKey;
            Dictionary <string, string> ErrorMessageList = new Dictionary <string, string>();
            PreFilledAnswerResponse     response;


            SurveyResponseBO            SurveyResponse = new SurveyResponseBO();
            UserAuthenticationRequestBO UserAuthenticationRequestBO = new  UserAuthenticationRequestBO();

            bool IsValidOrgKeyAndPublishKey = IsSurveyInfoValidByOrgKeyAndPublishKey(SurveyId, OrganizationId, UserPublishKey);


            if (IsValidOrgKeyAndPublishKey)
            {
                //Get Survey Info (MetaData)
                List <SurveyInfoBO> SurveyBOList = GetSurveyInfo(request);
                //Build Survey Response Xml

                string Xml = CreateResponseXml(request, SurveyBOList);
                //Validate Response values
                var responseid = request.AnswerInfo.SurveyQuestionAnswerList.Where(x => x.Key.ToLower() == "responseid" || x.Key.ToLower() == "id").FirstOrDefault();
                if (responseid.Key != null)
                {
                    request.AnswerInfo.SurveyQuestionAnswerList.Remove(responseid.Key);
                }
                var relateparentid = request.AnswerInfo.SurveyQuestionAnswerList.Where(x => x.Key.ToLower() == "fkey").FirstOrDefault();
                if (relateparentid.Key != null)
                {
                    request.AnswerInfo.SurveyQuestionAnswerList.Remove(relateparentid.Key);
                }

                var updatedtime = request.AnswerInfo.SurveyQuestionAnswerList.Where(x => x.Key.ToLower() == "_updatestamp").FirstOrDefault();
                if (updatedtime.Key != null)
                {
                    request.AnswerInfo.SurveyQuestionAnswerList.Remove(updatedtime.Key);
                }

                ErrorMessageList = ValidateResponse(SurveyBOList, request);

                if (ErrorMessageList.Count() > 0)
                {
                    response = new Epi.Web.Common.Message.PreFilledAnswerResponse();
                    response.ErrorMessageList = ErrorMessageList;
                    response.Status           = ((Message)1).ToString();
                }
                if (responseid.Value == null && updatedtime.Value == null)
                {
                    //Insert Survey Response

                    SurveyResponse = InsertSurveyResponse(Mapper.ToBusinessObject(Xml, request.AnswerInfo.SurveyId.ToString()));
                }
                else
                {//Insert  Response Api
                    if (relateparentid.Value == null)
                    {
                        SurveyResponseBO surveyresponseBO = new SurveyResponseBO();
                        surveyresponseBO.SurveyId       = request.AnswerInfo.SurveyId.ToString();
                        surveyresponseBO.ResponseId     = responseid.Value.ToString();
                        surveyresponseBO.XML            = Xml;
                        surveyresponseBO.Status         = 3;
                        surveyresponseBO.RecrodSourceId = (int)ValidationRecordSourceId.MA;
                        System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                        if (updatedtime.Value != null)
                        {
                            surveyresponseBO.DateUpdated = dateTime.AddMilliseconds(Convert.ToDouble(updatedtime.Value.ToString())).ToLocalTime();
                        }
                        else
                        {
                            surveyresponseBO.DateUpdated = DateTime.Now;
                        }
                        surveyresponseBO.DateCreated   = surveyresponseBO.DateUpdated;
                        surveyresponseBO.DateCompleted = surveyresponseBO.DateUpdated;
                        SurveyResponse = InsertSurveyResponseApi(surveyresponseBO);
                    }
                    else
                    {
                        try
                        {
                            var survey = GetSurveyResponseById(new List <string> {
                                relateparentid.Value
                            }, UserPublishKey);
                        }
                        catch (Exception ex)//insert parent response
                        {
                            SurveyResponseBO surveyresponsebO = new SurveyResponseBO();
                            surveyresponsebO.SurveyId       = SurveyBOList[0].ParentId;
                            surveyresponsebO.ResponseId     = relateparentid.Value.ToString();
                            surveyresponsebO.XML            = "  ";
                            surveyresponsebO.Status         = 3;
                            surveyresponsebO.RecrodSourceId = (int)ValidationRecordSourceId.MA;
                            surveyresponsebO.DateUpdated    = DateTime.Now;
                            surveyresponsebO.DateCreated    = surveyresponsebO.DateUpdated;
                            surveyresponsebO.DateCompleted  = surveyresponsebO.DateUpdated;
                            surveyresponsebO = InsertSurveyResponseApi(surveyresponsebO);
                        }
                        //insert child response
                        SurveyResponseBO surveyresponseBO = new SurveyResponseBO();
                        surveyresponseBO.SurveyId       = request.AnswerInfo.SurveyId.ToString();
                        surveyresponseBO.ResponseId     = responseid.Value.ToString();
                        surveyresponseBO.XML            = Xml;
                        surveyresponseBO.Status         = 3;
                        surveyresponseBO.RecrodSourceId = (int)ValidationRecordSourceId.MA;
                        surveyresponseBO.RelateParentId = relateparentid.Value;
                        System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                        if (updatedtime.Value != null)
                        {
                            surveyresponseBO.DateUpdated = dateTime.AddMilliseconds(Convert.ToDouble(updatedtime.Value.ToString())).ToLocalTime();
                        }
                        else
                        {
                            surveyresponseBO.DateUpdated = DateTime.Now;
                        }
                        surveyresponseBO.DateCreated   = surveyresponseBO.DateUpdated;
                        surveyresponseBO.DateCompleted = surveyresponseBO.DateUpdated;
                        SurveyResponse = InsertSurveyResponseApi(surveyresponseBO);
                    }
                }

                //Save PassCode

                UserAuthenticationRequestBO = Mapper.ToBusinessObject(SurveyResponse.ResponseId);
                SavePassCode(UserAuthenticationRequestBO);

                //return Response
                string ResponseUrl = ConfigurationManager.AppSettings["ResponseURL"];
                response = new  PreFilledAnswerResponse(Mapper.ToDataTransferObjects(UserAuthenticationRequestBO));
                response.SurveyResponseUrl = ResponseUrl + UserAuthenticationRequestBO.ResponseId;
                response.Status            = ((Message)2).ToString();;
            }

            else
            {
                PassCodeDTO DTOList = new   PassCodeDTO();
                response = new PreFilledAnswerResponse(DTOList);
                ErrorMessageList.Add("Keys", "Organization key and/or User publish key are invalid.");
                response.ErrorMessageList = ErrorMessageList;
                response.Status           = ((Message)1).ToString();
            }
            return(response);
        }