Example #1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OS_SS_1352 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue             = new FR_Guid();
            var template                = new ORM_CMN_QST_Questionnaire_Template();
            var templateVersion         = new ORM_CMN_QST_Questionnaire_Template_Version();
            var questionnaireAssignment = new ORM_CMN_PRO_Product_Questionnaire_Assignment();

            var result1 = template.Load(Connection, Transaction, Parameter.CMN_QST_Questionnaire_TemplateID);
            if (result1.Status != FR_Status.Success || template.CMN_QST_Questionnaire_TemplateID == Guid.Empty)
            {
                var error = new FR_Guid();
                error.ErrorMessage = "No Such ID";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            var result2 = templateVersion.Load(Connection, Transaction, template.Current_UnpublishedVersion_RefID);
            if (result2.Status != FR_Status.Success || templateVersion.CMN_QST_Questionnaire_Template_VersionID == Guid.Empty)
            {
                var error = new FR_Guid();
                error.ErrorMessage = "No Such ID";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            var result3 = questionnaireAssignment.Load(Connection, Transaction, Parameter.CMN_PRO_Product_Questionnaire_AssignmentID);
            if (result3.Status != FR_Status.Success || questionnaireAssignment.CMN_PRO_Product_Questionnaire_AssignmentID == Guid.Empty)
            {
                var error = new FR_Guid();
                error.ErrorMessage = "No Such ID";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }


            template.Current_PublishedVersion_RefID          = template.Current_UnpublishedVersion_RefID;
            templateVersion.IsQuestionnaireVersion_Published = true;

            #region Template Version +  unpublished version of a Template

            var templateVersionNew = new ORM_CMN_QST_Questionnaire_Template_Version();


            templateVersionNew.CMN_QST_Questionnaire_Template_VersionID = Guid.NewGuid();
            templateVersionNew.QuestionnaireTemplate_RefID      = template.CMN_QST_Questionnaire_TemplateID;
            templateVersionNew.IsQuestionnaireVersion_Published = false;
            templateVersionNew.Tenant_RefID           = securityTicket.TenantID;
            templateVersionNew.Creation_Account_RefID = securityTicket.AccountID;
            templateVersionNew.Tenant_RefID           = securityTicket.TenantID;

            template.Current_UnpublishedVersion_RefID = templateVersionNew.CMN_QST_Questionnaire_Template_VersionID;

            template.Save(Connection, Transaction);
            templateVersion.Save(Connection, Transaction);
            templateVersionNew.Save(Connection, Transaction);
            #endregion

            #region set old questionnare Assigment to false  and create  new Questionnaire Assignment

            questionnaireAssignment.IsActive = true;
            questionnaireAssignment.Save(Connection, Transaction);

            var questionnaireAssignmentNew = new ORM_CMN_PRO_Product_Questionnaire_Assignment();
            questionnaireAssignmentNew.CMN_PRO_Product_Questionnaire_AssignmentID = Guid.NewGuid();
            questionnaireAssignmentNew.CMN_PRO_Product_RefID = questionnaireAssignment.CMN_PRO_Product_RefID;
            questionnaireAssignmentNew.CMN_QST_Questionnaire_Template_Version_RefID = templateVersionNew.CMN_QST_Questionnaire_Template_VersionID;
            questionnaireAssignmentNew.Tenant_RefID = securityTicket.TenantID;
            questionnaireAssignmentNew.IsActive     = false;
            questionnaireAssignmentNew.Tenant_RefID = securityTicket.TenantID;
            questionnaireAssignmentNew.Save(Connection, Transaction);
            #endregion

            #region Question items , Enumeration Answers and answers

            var query = new ORM_CMN_QST_Questionnaire_QuestionItem.Query();
            query.Questionnaire_Template_RefID = templateVersion.CMN_QST_Questionnaire_Template_VersionID;

            var questionItemsAll = ORM_CMN_QST_Questionnaire_QuestionItem.Query.Search(Connection, Transaction, query).ToList();

            for (int i = 0; i < questionItemsAll.Count; i++)
            {
                ORM_CMN_QST_QuestionItem_EnumerationAnswerType questionItemEnumerationAnswerTypes = new ORM_CMN_QST_QuestionItem_EnumerationAnswerType();
                questionItemEnumerationAnswerTypes.EnumerationAnswerType_Name = new Dict();
                questionItemEnumerationAnswerTypes.EnumerationAnswerType_Name.DictionaryID = Guid.NewGuid();;
                questionItemEnumerationAnswerTypes.Tenant_RefID = securityTicket.TenantID;
                questionItemEnumerationAnswerTypes.Save(Connection, Transaction);

                ORM_CMN_QST_Questionnaire_QuestionItem quetionItem = new ORM_CMN_QST_Questionnaire_QuestionItem();
                quetionItem.Questionnaire_Template_RefID = templateVersionNew.CMN_QST_Questionnaire_Template_VersionID;
                quetionItem.QuestionItem_Label           = questionItemsAll[i].QuestionItem_Label.CopyContents("ORM_CMN_QST_Questionnaire_QuestionItem");
                quetionItem.IsDeleted = questionItemsAll[i].IsDeleted;
                quetionItem.QuestionItem_Description    = questionItemsAll[i].QuestionItem_Description.CopyContents("ORM_CMN_QST_Questionnaire_QuestionItem");
                quetionItem.IsAnswer_Enum               = questionItemsAll[i].IsAnswer_Enum;
                quetionItem.Tenant_RefID                = questionItemsAll[i].Tenant_RefID;
                quetionItem.QuestionItem_SequenceNumber = questionItemsAll[i].QuestionItem_SequenceNumber;
                quetionItem.IfAnswer_EnumType_RefID     = questionItemEnumerationAnswerTypes.CMN_QST_QuestionItem_EnumerationAnswerTypeID;
                quetionItem.Save(Connection, Transaction);

                var query2 = new ORM_CMN_QST_QuestionItem_EnumerationAnswer.Query();
                query2.EnumerationAnswerType_RefID = questionItemsAll[i].IfAnswer_EnumType_RefID;

                var answers = ORM_CMN_QST_QuestionItem_EnumerationAnswer.Query.Search(Connection, Transaction, query2);

                if (answers.Count() != 2)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "There are no answers in DataBase!";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                ORM_CMN_QST_QuestionItem_EnumerationAnswer answr1 = answers.OrderBy(a => a.Creation_Timestamp).First();
                ORM_CMN_QST_QuestionItem_EnumerationAnswer answr2 = answers.OrderBy(a => a.Creation_Timestamp).Last();

                /*######Answer 1  ###########*/
                var enumerationAnswer1 = new ORM_CMN_QST_QuestionItem_EnumerationAnswer();
                enumerationAnswer1.EnumerationAnswerType_RefID = questionItemEnumerationAnswerTypes.CMN_QST_QuestionItem_EnumerationAnswerTypeID;
                enumerationAnswer1.EnumerationAnswer_Text      = answr1.EnumerationAnswer_Text.CopyContents("ORM_CMN_QST_QuestionItem_EnumerationAnswer");
                enumerationAnswer1.Tenant_RefID       = securityTicket.TenantID;
                enumerationAnswer1.Creation_Timestamp = DateTime.Now;
                enumerationAnswer1.Save(Connection, Transaction);

                /*######Answer 2  ###########*/
                var enumerationAnswer2 = new ORM_CMN_QST_QuestionItem_EnumerationAnswer();
                enumerationAnswer2.EnumerationAnswerType_RefID = questionItemEnumerationAnswerTypes.CMN_QST_QuestionItem_EnumerationAnswerTypeID;
                enumerationAnswer2.EnumerationAnswer_Text      = answr2.EnumerationAnswer_Text.CopyContents("ORM_CMN_QST_QuestionItem_EnumerationAnswer");
                enumerationAnswer2.Tenant_RefID       = securityTicket.TenantID;
                enumerationAnswer2.Creation_Timestamp = DateTime.Now.AddMinutes(1);
                enumerationAnswer2.Save(Connection, Transaction);
            }
            #endregion
            return(returnValue);

            #endregion UserCode
        }
Example #2
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OS_SS_1614 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var     returnValue  = new FR_Guid();
            Boolean IsFirstInput = false;

            var template                = new ORM_CMN_QST_Questionnaire_Template();
            var templateVersion         = new ORM_CMN_QST_Questionnaire_Template_Version();
            var questionnaireAssignment = new ORM_CMN_PRO_Product_Questionnaire_Assignment();

            //Isn't First Input
            if (Parameter.CMN_QST_Questionnaire_TemplateID != Guid.Empty)
            {
                var result1 = template.Load(Connection, Transaction, Parameter.CMN_QST_Questionnaire_TemplateID);
                if (result1.Status != FR_Status.Success || template.CMN_QST_Questionnaire_TemplateID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }

                var result2 = templateVersion.Load(Connection, Transaction, template.Current_UnpublishedVersion_RefID);
                if (result2.Status != FR_Status.Success || templateVersion.CMN_QST_Questionnaire_Template_VersionID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }

                //var result3 = questionnaireAssignment.Load(Connection, Transaction, questionnaireAssignment.CMN_PRO_Product_Questionnaire_AssignmentID);
                //if (result3.Status != FR_Status.Success || questionnaireAssignment.CMN_PRO_Product_Questionnaire_AssignmentID == Guid.Empty)
                //{
                //    var error = new FR_Guid();
                //    error.ErrorMessage = "No Such ID";
                //    error.Status = FR_Status.Error_Internal;
                //    return error;
                //}
            }
            else
            {
                IsFirstInput = true;

                #region Template

                template.CMN_QST_Questionnaire_TemplateID  = Guid.NewGuid();
                template.QuestionnaireTemplate_Description = new Dict();

                template.Tenant_RefID = securityTicket.TenantID;

                #endregion

                #region Template Version + setting Current published and unpublished version of a Template


                templateVersion.CMN_QST_Questionnaire_Template_VersionID = Guid.NewGuid();
                templateVersion.QuestionnaireTemplate_RefID      = template.CMN_QST_Questionnaire_TemplateID;
                templateVersion.IsQuestionnaireVersion_Published = false;
                templateVersion.Tenant_RefID           = securityTicket.TenantID;
                templateVersion.Creation_Account_RefID = securityTicket.AccountID;

                template.Current_PublishedVersion_RefID   = Guid.Empty;
                template.Current_UnpublishedVersion_RefID = templateVersion.CMN_QST_Questionnaire_Template_VersionID;

                #endregion



                #region Questionnaire Assignment

                questionnaireAssignment.CMN_PRO_Product_Questionnaire_AssignmentID = Guid.NewGuid();
                questionnaireAssignment.CMN_PRO_Product_RefID = Parameter.CMN_PRO_Product_RefID;
                questionnaireAssignment.CMN_QST_Questionnaire_Template_Version_RefID = templateVersion.CMN_QST_Questionnaire_Template_VersionID;
                questionnaireAssignment.Tenant_RefID = securityTicket.TenantID;
                questionnaireAssignment.IsActive     = false;
                #endregion

                questionnaireAssignment.Save(Connection, Transaction);
                template.Save(Connection, Transaction);
                templateVersion.Save(Connection, Transaction);
            }

            //Add
            if (Parameter.CMN_QST_Questionnaire_ItemID == Guid.Empty)
            {
                #region Question Item

                var quetionItem = new ORM_CMN_QST_Questionnaire_QuestionItem();
                quetionItem.CMN_QST_Questionnaire_ItemID = Guid.NewGuid();

                quetionItem.Questionnaire_Template_RefID = templateVersion.CMN_QST_Questionnaire_Template_VersionID;
                quetionItem.QuestionItem_Label           = Parameter.QuestionItem_Label_DictID;
                quetionItem.IsDeleted = Parameter.IsDeleted;
                quetionItem.QuestionItem_Description = new Dict();
                quetionItem.IsAnswer_Enum            = true;
                quetionItem.Tenant_RefID             = securityTicket.TenantID;

                var query = new ORM_CMN_QST_Questionnaire_QuestionItem.Query();

                query.Questionnaire_Template_RefID = templateVersion.CMN_QST_Questionnaire_Template_VersionID;
                var questionItemsAll = ORM_CMN_QST_Questionnaire_QuestionItem.Query.Search(Connection, Transaction, query).ToList();

                quetionItem.QuestionItem_SequenceNumber = questionItemsAll.Count + 1;

                #endregion

                #region Enumeration Answers

                var questionItemEnumerationAnswerTypes = new ORM_CMN_QST_QuestionItem_EnumerationAnswerType();

                questionItemEnumerationAnswerTypes.CMN_QST_QuestionItem_EnumerationAnswerTypeID = Guid.NewGuid();
                questionItemEnumerationAnswerTypes.EnumerationAnswerType_Name = new Dict();

                quetionItem.IfAnswer_EnumType_RefID = questionItemEnumerationAnswerTypes.CMN_QST_QuestionItem_EnumerationAnswerTypeID;
                quetionItem.Tenant_RefID            = securityTicket.TenantID;


                DateTime timeNow = DateTime.Now;

                /*######Answer 1  ###########*/
                var enumerationAnswer1 = new ORM_CMN_QST_QuestionItem_EnumerationAnswer();

                enumerationAnswer1.CMN_QST_QuestionItem_EnumerationAnswerID = Guid.NewGuid();
                enumerationAnswer1.EnumerationAnswerType_RefID = questionItemEnumerationAnswerTypes.CMN_QST_QuestionItem_EnumerationAnswerTypeID;
                enumerationAnswer1.EnumerationAnswer_Text      = Parameter.EnumerationAnswer_Text_First_DictID;
                enumerationAnswer1.Creation_Timestamp          = timeNow;
                enumerationAnswer1.Tenant_RefID = securityTicket.TenantID;

                /*######Answer 2  ###########*/

                var enumerationAnswer2 = new ORM_CMN_QST_QuestionItem_EnumerationAnswer();

                enumerationAnswer2.CMN_QST_QuestionItem_EnumerationAnswerID = Guid.NewGuid();
                enumerationAnswer2.EnumerationAnswerType_RefID = questionItemEnumerationAnswerTypes.CMN_QST_QuestionItem_EnumerationAnswerTypeID;
                enumerationAnswer2.EnumerationAnswer_Text      = Parameter.EnumerationAnswer_Text_Second_DictID;
                enumerationAnswer2.Creation_Timestamp          = timeNow.AddMinutes(1);
                enumerationAnswer2.Tenant_RefID = securityTicket.TenantID;

                #endregion


                enumerationAnswer1.Save(Connection, Transaction);
                enumerationAnswer2.Save(Connection, Transaction);
                questionItemEnumerationAnswerTypes.Save(Connection, Transaction);
                quetionItem.Save(Connection, Transaction);
            }
            else
            {
                #region Question Item

                var questionItem = new ORM_CMN_QST_Questionnaire_QuestionItem();
                questionItem.Load(Connection, Transaction, Parameter.CMN_QST_Questionnaire_ItemID);
                questionItem.QuestionItem_Label = Parameter.QuestionItem_Label_DictID;
                questionItem.IsDeleted          = Parameter.IsDeleted;
                questionItem.Save(Connection, Transaction);

                #endregion

                #region Enumeration Answers Type

                var questionItemEnumerationAnswerTypes = new ORM_CMN_QST_QuestionItem_EnumerationAnswerType();
                questionItemEnumerationAnswerTypes.Load(Connection, Transaction, questionItem.IfAnswer_EnumType_RefID);


                #endregion Enumeration Answers Type

                #region Enumeration Answers

                var query = new ORM_CMN_QST_QuestionItem_EnumerationAnswer.Query();
                query.EnumerationAnswerType_RefID = questionItemEnumerationAnswerTypes.CMN_QST_QuestionItem_EnumerationAnswerTypeID;

                var answers = ORM_CMN_QST_QuestionItem_EnumerationAnswer.Query.Search(Connection, Transaction, query);

                if (answers.Count() != 2)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "There are no answers in DataBase!";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }

                answers[0].EnumerationAnswer_Text = Parameter.EnumerationAnswer_Text_First_DictID;
                answers[0].Save(Connection, Transaction);

                answers[1].EnumerationAnswer_Text = Parameter.EnumerationAnswer_Text_Second_DictID;
                answers[1].Save(Connection, Transaction);


                #endregion
            }

            return(returnValue);

            #endregion UserCode
        }