Exemple #1
0
        /// <summary>
        /// Set (add, update, delete) SurveyInfo value.
        /// </summary>
        /// <param name="request">SurveyInfoRequest request message.</param>
        /// <returns>SurveyInfoRequest response message.</returns>
        public SurveyInfoResponse SetSurveyInfo(SurveyInfoRequest request)
        {
            try
            {
                Epi.Web.Interfaces.DataInterfaces.ISurveyInfoDao surveyInfoDao = new EF.EntitySurveyInfoDao();
                Epi.Web.BLL.SurveyInfo Implementation = new Epi.Web.BLL.SurveyInfo(surveyInfoDao);


                var response = new SurveyInfoResponse(request.RequestId);

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

                // Transform SurveyInfo data transfer object to SurveyInfo business object
                var SurveyInfo = Mapper.ToBusinessObject(request.SurveyInfoList[0]);

                // Validate SurveyInfo business rules

                if (request.Action != "Delete")
                {
                    //if (!SurveyInfo.Validate())
                    //{
                    //    response.Acknowledge = AcknowledgeType.Failure;

                    //    foreach (string error in SurveyInfo.ValidationErrors)
                    //        response.Message += error + Environment.NewLine;

                    //    return response;
                    //}
                }

                // Run within the context of a database transaction. Currently commented out.
                // The Decorator Design Pattern.
                //using (TransactionDecorator transaction = new TransactionDecorator())
                {
                    if (request.Action == "Create")
                    {
                        if (request.Criteria.FileInputStream == null)
                        {
                            Implementation.InsertSurveyInfo(SurveyInfo);
                            response.SurveyInfoList.Add(Mapper.ToDataTransferObject(SurveyInfo));
                        }
                        else
                        {
                            // Excel
                            string SurveyFile = Implementation.GetSurveyXml(request.Criteria.FileInputStream);
                            SurveyInfo.XML = SurveyFile;
                            Implementation.InsertSurveyInfo(SurveyInfo);
                            response.SurveyInfoList.Add(Mapper.ToDataTransferObject(SurveyInfo));
                        }
                    }
                    else if (request.Action == "Update")
                    {
                        if (request.Criteria.FileInputStream == null)
                        {
                            Implementation.UpdateSurveyInfo(SurveyInfo);
                            response.SurveyInfoList.Add(Mapper.ToDataTransferObject(SurveyInfo));
                        }
                        else
                        {
                            // Excel
                            string SurveyFile = Implementation.GetSurveyXml(request.Criteria.FileInputStream);
                            SurveyInfo.XML = SurveyFile;
                            Implementation.UpdateSurveyInfo(SurveyInfo);
                            response.SurveyInfoList.Add(Mapper.ToDataTransferObject(SurveyInfo));
                        }
                    }
                    else if (request.Action == "Delete")
                    {
                        var criteria = request.Criteria as SurveyInfoCriteria;
                        var survey   = Implementation.GetSurveyInfoById(SurveyInfo.SurveyId);

                        try
                        {
                            if (Implementation.DeleteSurveyInfo(survey))
                            {
                                response.RowsAffected = 1;
                            }
                            else
                            {
                                response.RowsAffected = 0;
                            }
                        }
                        catch
                        {
                            response.RowsAffected = 0;
                        }
                    }
                }

                return(response);
            }
            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);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        public SurveyAnswerResponse GetSurveyAnswer(SurveyAnswerRequest pRequest)
        {
            try
            {
                SurveyAnswerResponse result = new SurveyAnswerResponse(pRequest.RequestId);
                //Epi.Web.Enter.Interfaces.DataInterfaces.ISurveyResponseDao surveyInfoDao = new EF.EntitySurveyResponseDao();
                //Epi.Web.BLL.SurveyResponse Implementation = new Epi.Web.BLL.SurveyResponse(surveyInfoDao);

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



                //Get Organization Info
                Epi.Web.Enter.Interfaces.DataInterfaces.IOrganizationDao entityDaoFactory1 = new EF.EntityOrganizationDao();
                //Epi.Web.Enter.Interfaces.DataInterfaces.ISurveyInfoDao surveyInfoDao = entityDaoFactory.SurveyInfoDao;
                Epi.Web.Enter.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.Enter.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, criteria.UserId);

                    //}

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

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


                        List <string> IdList = new List <string>();

                        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.StatusId,
                                criteria.IsDraftMode
                                                                           );



                            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
                    {
                        if (criteria.UserId != -1 && criteria.UserPublishKey == Guid.Empty)
                        {
                            result.Message = "InvalidUserId";
                        }
                        if (criteria.UserId == -1 && criteria.UserPublishKey != Guid.Empty)
                        {
                            result.Message = "InvalidPublishKey";
                        }
                    }
                }
                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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Set (add, update, delete) SurveyInfo value.
        /// </summary>
        /// <param name="request">SurveyResponse request message.</param>
        /// <returns>SurveyResponse response message.</returns>
        public SurveyAnswerResponse SetSurveyAnswer(SurveyAnswerRequest request)
        {
            try
            {
                Epi.Web.Interfaces.DataInterfaces.ISurveyResponseDao SurveyResponseDao = new EF.EntitySurveyResponseDao();
                Epi.Web.Interfaces.DataInterfaces.ISurveyInfoDao     ISurveyInfoDao    = new EF.EntitySurveyInfoDao();

                Epi.Web.BLL.SurveyResponse Implementation = new Epi.Web.BLL.SurveyResponse(SurveyResponseDao, ISurveyInfoDao);


                SurveyAnswerResponse response = new SurveyAnswerResponse(request.RequestId);

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

                // Transform SurveyResponse data transfer object to SurveyResponse business object
                SurveyResponseBO SurveyResponse = Mapper.ToBusinessObject(request.SurveyAnswerList)[0];

                // Validate SurveyResponse business rules

                if (request.Action != "Delete")
                {
                    //if (!SurveyResponse.Validate())
                    //{
                    //    response.Acknowledge = AcknowledgeType.Failure;

                    //    foreach (string error in SurveyResponse.ValidationErrors)
                    //        response.Message += error + Environment.NewLine;

                    //    return response;
                    //}
                }

                // Run within the context of a database transaction. Currently commented out.
                // The Decorator Design Pattern.
                //using (TransactionDecorator transaction = new TransactionDecorator())
                {
                    if (request.Action.Equals("Create", StringComparison.OrdinalIgnoreCase))
                    {
                        Implementation.InsertSurveyResponse(SurveyResponse);
                        response.SurveyResponseList.Add(Mapper.ToDataTransferObject(SurveyResponse));
                    }
                    else if (request.Action.Equals("CreateChild", StringComparison.OrdinalIgnoreCase))
                    {
                        Epi.Web.Interfaces.DataInterfaces.ISurveyInfoDao SurveyInfoDao = new EF.EntitySurveyInfoDao();
                        Epi.Web.BLL.SurveyInfo Implementation1 = new Epi.Web.BLL.SurveyInfo(SurveyInfoDao);
                        SurveyInfoBO           SurveyInfoBO    = Implementation1.GetParentInfoByChildId(SurveyResponse.SurveyId);

                        Implementation.InsertChildSurveyResponse(SurveyResponse, SurveyInfoBO, request.SurveyAnswerList[0].RelateParentId);
                        response.SurveyResponseList.Add(Mapper.ToDataTransferObject(SurveyResponse));

                        List <SurveyResponseBO> List = new List <SurveyResponseBO>();
                        List.Add(SurveyResponse);
                        Implementation.InsertSurveyResponse(List, request.Criteria.UserId, true);
                    }
                    else if (request.Action.Equals("Update", StringComparison.OrdinalIgnoreCase))
                    {
                        Implementation.UpdateSurveyResponse(SurveyResponse);
                        response.SurveyResponseList.Add(Mapper.ToDataTransferObject(SurveyResponse));
                    }
                    else if (request.Action.Equals("Delete", StringComparison.OrdinalIgnoreCase))
                    {
                        var criteria = request.Criteria as SurveyAnswerCriteria;
                        var survey   = Implementation.GetSurveyResponseById(new List <string> {
                            SurveyResponse.SurveyId
                        }, SurveyResponse.UserPublishKey);

                        foreach (SurveyResponseBO surveyResponse in survey)
                        {
                            try
                            {
                                if (Implementation.DeleteSurveyResponse(surveyResponse))
                                {
                                    response.RowsAffected += 1;
                                }
                            }
                            catch
                            {
                                //response.RowsAffected = 0;
                            }
                        }
                    }
                }

                return(response);
            }
            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);
            }
        }
        /// <summary>
        /// Set (add, update, delete) SurveyInfo value.
        /// </summary>
        /// <param name="request">SurveyInfoRequest request message.</param>
        /// <returns>SurveyInfoRequest response message.</returns>
        public SurveyInfoResponse SetSurveyInfo(SurveyInfoRequest request)
        {
            try
            {
                Epi.Web.Enter.Interfaces.DataInterfaces.ISurveyInfoDao surveyInfoDao = new EF.EntitySurveyInfoDao();

                Epi.Web.BLL.SurveyInfo Implementation = new Epi.Web.BLL.SurveyInfo(surveyInfoDao);



                var response = new SurveyInfoResponse(request.RequestId);

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

                // Transform SurveyInfo data transfer object to SurveyInfo business object
                var SurveyInfo = Mapper.ToBusinessObject(request.SurveyInfoList[0]);

                // Validate SurveyInfo business rules

                if (request.Action != "Delete")
                {
                    //if (!SurveyInfo.Validate())
                    //{
                    //    response.Acknowledge = AcknowledgeType.Failure;

                    //    foreach (string error in SurveyInfo.ValidationErrors)
                    //        response.Message += error + Environment.NewLine;

                    //    return response;
                    //}
                }

                // Run within the context of a database transaction. Currently commented out.
                // The Decorator Design Pattern.
                //using (TransactionDecorator transaction = new TransactionDecorator())
                {
                    bool validSurvey = false;
                    //GetSurveyInfoByOrgKey
                    //validSurvey = Implementation.IsSurveyInfoValidByOrgKeyAndPublishKey(SurveyInfo.SurveyId, SurveyInfo.OrganizationKey.ToString(), SurveyInfo.UserPublishKey);
                    validSurvey = Implementation.IsSurveyInfoValidByOrgKey(SurveyInfo.SurveyId, SurveyInfo.OrganizationKey.ToString());

                    Epi.Web.Enter.Interfaces.DataInterfaces.IOrganizationDao entityDaoFactory1 = new EF.EntityOrganizationDao();
                    Epi.Web.Enter.Interfaces.DataInterfaces.IOrganizationDao surveyInfoDao1    = entityDaoFactory1;
                    Epi.Web.BLL.Organization implementation1 = new Epi.Web.BLL.Organization(surveyInfoDao1);
                    bool ISValidOrg = implementation1.ValidateOrganization(SurveyInfo.OrganizationKey.ToString());

                    if (ISValidOrg)
                    {
                        if (validSurvey)
                        {
                            if (request.Action == "Create")
                            {
                                Implementation.InsertSurveyInfo(SurveyInfo);
                                response.SurveyInfoList.Add(Mapper.ToDataTransferObject(SurveyInfo));
                            }
                            else if (request.Action == "Update")
                            {
                                Implementation.UpdateSurveyInfo(SurveyInfo);
                                response.SurveyInfoList.Add(Mapper.ToDataTransferObject(SurveyInfo));
                                response.Message = SurveyInfo.StatusText;
                            }
                            else if (request.Action == "UpdateMode")
                            {
                                Implementation.UpdateSurveyInfo(SurveyInfo);
                                response.SurveyInfoList.Add(Mapper.ToDataTransferObject(SurveyInfo));
                                response.Message = SurveyInfo.StatusText;
                                //ImplementationAdmin.SendEmailToAdmins(SurveyInfo);// This process does not apply for EWE.
                            }
                            else if (request.Action == "Delete")
                            {
                                var criteria = request.Criteria as SurveyInfoCriteria;
                                var survey   = Implementation.GetSurveyInfoById(SurveyInfo.SurveyId);

                                try
                                {
                                    if (Implementation.DeleteSurveyInfo(survey))
                                    {
                                        response.RowsAffected = 1;
                                    }
                                    else
                                    {
                                        response.RowsAffected = 0;
                                    }
                                }
                                catch
                                {
                                    response.RowsAffected = 0;
                                }
                            }
                        }
                        else
                        {
                            response.Message = "SurveyId And/or Publish Key are invalid.";
                        }
                    }
                    else
                    {
                        response.Message = "Organization Key is invalid.";
                    }
                }

                return(response);
            }
            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);
            }
        }