Example #1
0
 public SurveyInfo(Interfaces.DataInterfaces.ISurveyInfoDao pSurveyInfoDao)
 {
     this.SurveyInfoDao = pSurveyInfoDao;
 }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        public SurveyAnswerResponse GetSurveyAnswer(SurveyAnswerRequest pRequest)
        {
            try
            {
                SurveyAnswerResponse result = new SurveyAnswerResponse(pRequest.RequestId);
                //Epi.Web.Interfaces.DataInterfaces.ISurveyResponseDao surveyInfoDao = new EF.EntitySurveyResponseDao();
                //Epi.Web.BLL.SurveyResponse Implementation = new Epi.Web.BLL.SurveyResponse(surveyInfoDao);

                Epi.Web.Interfaces.DataInterfaces.IDaoFactory        entityDaoFactory   = new EF.EntityDaoFactory();
                Epi.Web.Interfaces.DataInterfaces.ISurveyResponseDao ISurveyResponseDao = entityDaoFactory.SurveyResponseDao;
                Interfaces.DataInterfaces.ISurveyInfoDao             ISurveyInfoDao     = entityDaoFactory.SurveyInfoDao;
                Epi.Web.BLL.SurveyResponse Implementation = new Epi.Web.BLL.SurveyResponse(ISurveyResponseDao, ISurveyInfoDao);



                //Get Organization Info
                Epi.Web.Interfaces.DataInterfaces.IOrganizationDao entityDaoFactory1 = new EF.EntityOrganizationDao();
                //Epi.Web.Interfaces.DataInterfaces.ISurveyInfoDao surveyInfoDao = entityDaoFactory.SurveyInfoDao;
                Epi.Web.Interfaces.DataInterfaces.IOrganizationDao surveyInfoDao1 = entityDaoFactory1;

                Epi.Web.BLL.Organization implementation1 = new Epi.Web.BLL.Organization(surveyInfoDao1);

                bool ISValidOrg = implementation1.ValidateOrganization(pRequest.Criteria.OrganizationKey.ToString());



                if (ISValidOrg)

                {
                    // Validate client tag, access token, and user credentials
                    if (!ValidRequest(pRequest, result, Validate.All))
                    {
                        return(result);
                    }

                    SurveyAnswerCriteria criteria = pRequest.Criteria;


                    if (criteria.UserPublishKey == null)
                    {
                        return(result);
                    }


                    Epi.Web.Interfaces.DataInterfaces.ISurveyInfoDao surveyInfoDao = new EF.EntitySurveyInfoDao();
                    Epi.Web.BLL.SurveyInfo SurveyInfo = new Epi.Web.BLL.SurveyInfo(surveyInfoDao);



                    //List<string> SurveyIdList = new List<string>();

                    //SurveyIdList.Add(criteria.SurveyId);


                    bool validSurvey = false;
                    // if (string.IsNullOrEmpty(criteria.SurveyId.ToString()))
                    // {
                    validSurvey = SurveyInfo.IsSurveyInfoValidByOrgKeyAndPublishKey(criteria.SurveyId, criteria.OrganizationKey.ToString(), criteria.UserPublishKey);

                    //}

                    if (validSurvey == true)
                    {
                        //Guid UserPublishKey = SurveyInfo.GetSurveyInfoById(criteria.SurveyId).UserPublishKey;

                        //if (criteria.UserPublishKey != UserPublishKey)
                        //{
                        //    return result;
                        //}


                        List <string> IdList = new List <string>();
                        if (criteria.SurveyAnswerIdList != null)
                        {
                            foreach (string id in criteria.SurveyAnswerIdList)
                            {
                                IdList.Add(id.ToUpper());
                            }
                        }
                        //string sort = criteria.SortExpression;

                        //if (request.LoadOptions.Contains("SurveyInfos"))
                        //{
                        //    IEnumerable<SurveyInfoDTO> SurveyInfos;
                        //    if (!criteria.IncludeOrderStatistics)
                        //    {
                        //        SurveyInfos = Implementation.GetSurveyInfos(sort);
                        //    }
                        //    else
                        //    {
                        //        SurveyInfos = Implementation.GetSurveyInfosWithOrderStatistics(sort);
                        //    }

                        //    response.SurveyInfos = SurveyInfos.Select(c => Mapper.ToDataTransferObject(c)).ToList();
                        //}

                        int ResponseMaxSize = Int32.Parse(ConfigurationManager.AppSettings["maxBytesPerRead"]);

                        int BandwidthUsageFactor = Int32.Parse(ConfigurationManager.AppSettings["BandwidthUsageFactor"]);

                        if (pRequest.Criteria.ReturnSizeInfoOnly == true)
                        {
                            // call BLL with a list of records

                            PageInfoBO PageInfoBO = Implementation.GetResponseSurveySize(IdList, criteria.SurveyId, criteria.DateCompleted, BandwidthUsageFactor, criteria.IsDraftMode, criteria.StatusId, -1, -1, ResponseMaxSize);



                            result.PageSize      = PageInfoBO.PageSize;
                            result.NumberOfPages = PageInfoBO.NumberOfPages;
                        }
                        else
                        {
                            List <SurveyResponseBO> SurveyResponseBOList = Implementation.GetSurveyResponse
                                                                           (
                                IdList,
                                criteria.SurveyId,
                                criteria.DateCompleted,
                                criteria.IsDraftMode,
                                criteria.StatusId,
                                pRequest.Criteria.PageNumber,
                                pRequest.Criteria.PageSize
                                                                           );



                            foreach (SurveyResponseBO surveyResponseBo in SurveyResponseBOList)
                            {
                                // if (surveyResponseBo.UserPublishKey == criteria.UserPublishKey)
                                //if (UserPublishKey == criteria.UserPublishKey)
                                //{
                                result.SurveyResponseList.Add(Mapper.ToDataTransferObject(surveyResponseBo));
                                //  }
                            }
                        }

                        /*
                         * if (string.IsNullOrEmpty(pRequest.Criteria.SurveyId))
                         * {
                         *  result.SurveyResponseList = Mapper.ToDataTransferObject(Implementation.GetSurveyResponseById(pRequest.Criteria.SurveyAnswerIdList));
                         * }
                         * else
                         * {
                         *  result.SurveyResponseList = Mapper.ToDataTransferObject(Implementation.GetSurveyResponseBySurveyId(pRequest.Criteria.SurveyAnswerIdList));
                         * }*/
                    }
                    else
                    {
                        result.Message = "SurveyId or Organization Key or Publish Key are invalid.";
                    }
                }
                else
                {
                    result.Message = "Organization Key not found";
                }

                return(result);
            }
            catch (Exception ex)
            {
                CustomFaultException customFaultException = new CustomFaultException();
                customFaultException.CustomMessage = ex.Message;
                customFaultException.Source        = ex.Source;
                customFaultException.StackTrace    = ex.StackTrace;
                customFaultException.HelpLink      = ex.HelpLink;
                throw new FaultException <CustomFaultException>(customFaultException);
            }
        }