Пример #1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2RP_SRP_1421 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var item       = new ORM_LOG_RET_ReturnPolicy();
            var price      = new ORM_CMN_Price();
            var priceValue = new ORM_CMN_Price_Value();

            if (Parameter.LOG_RET_ReturnPolicyID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.LOG_RET_ReturnPolicyID);
                var price1 = price.Load(Connection, Transaction, item.ReturnPolicy_Cost_RefID);

                var query = new ORM_CMN_Price_Value.Query();
                query.Price_RefID = item.ReturnPolicy_Cost_RefID;
                priceValue        = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, query).First();

                if (result.Status != FR_Status.Success || item.LOG_RET_ReturnPolicyID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted       = true;
                price.IsDeleted      = true;
                priceValue.IsDeleted = true;
                price.Save(Connection, Transaction);
                priceValue.Save(Connection, Transaction);
                return(new FR_Guid(item.Save(Connection, Transaction), item.LOG_RET_ReturnPolicyID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.LOG_RET_ReturnPolicyID == Guid.Empty)
            {
                priceValue.Price_RefID = price.CMN_PriceID;
                //priceValue.PriceValue_Currency_RefID = Parameter.PriceValue_Currency_RefID;
                item.ReturnPolicy_Cost_RefID = price.CMN_PriceID;

                item.Tenant_RefID       = securityTicket.TenantID;
                price.Tenant_RefID      = securityTicket.TenantID;
                priceValue.Tenant_RefID = securityTicket.TenantID;
            }

            priceValue.PriceValue_Currency_RefID = Parameter.PriceValue_Currency_RefID;
            item.ReturnPolicy_Abbreviation       = Parameter.ReturnPolicy_Abbreviation;
            item.ReturnPolicy_Reason             = Parameter.ReturnPolicy_Reason_DictID;
            item.GlobalPropertyMatchingID        = Parameter.GlobalPropertyMatchingID;
            priceValue.PriceValue_Amount         = Parameter.PriceValue_Amount;
            price.Save(Connection, Transaction);
            priceValue.Save(Connection, Transaction);
            return(new FR_Guid(item.Save(Connection, Transaction), item.LOG_RET_ReturnPolicyID));

            #endregion UserCode
        }
Пример #2
0
        public static void Add_GPOSes_to_ContractTables(List <GPOS_Model> parameter, DbConnection Connection, DbTransaction Transaction, SessionSecurityTicket securityTicket)
        {
            var accountforTenant = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
            {
                IsDeleted     = false,
                USR_AccountID = securityTicket.AccountID,
                Tenant_RefID  = securityTicket.TenantID
            }).Single();

            var businessParticipantForTenant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID,
                CMN_BPT_BusinessParticipantID = accountforTenant.BusinessParticipant_RefID
            }).Single();

            var searchContractParties = ORM_CMN_CTR_Contract_Party.Query.Search(Connection, Transaction, new ORM_CMN_CTR_Contract_Party.Query()
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID,
                Undersigning_BusinessParticipant_RefID = businessParticipantForTenant.CMN_BPT_BusinessParticipantID
            }).ToList();
            Guid contractID = Guid.NewGuid();


            var catalog1 = new ORM_HEC_BIL_PotentialCode_Catalog();

            catalog1.IsDeleted    = false;
            catalog1.Tenant_RefID = securityTicket.TenantID;
            catalog1.HEC_BIL_PotentialCode_CatalogID = Guid.NewGuid();
            catalog1.GlobalPropertyMatchingID        = "mm.docconnect.gpos.catalog.operation";
            catalog1.Creation_Timestamp = DateTime.Now;
            catalog1.Save(Connection, Transaction);


            var catalog2 = new ORM_HEC_BIL_PotentialCode_Catalog();

            catalog2.IsDeleted    = false;
            catalog2.Tenant_RefID = securityTicket.TenantID;
            catalog2.HEC_BIL_PotentialCode_CatalogID = Guid.NewGuid();
            catalog2.GlobalPropertyMatchingID        = "mm.docconnect.gpos.catalog.nachsorge";
            catalog2.Creation_Timestamp = DateTime.Now;
            catalog2.Save(Connection, Transaction);

            var catalog3 = new ORM_HEC_BIL_PotentialCode_Catalog();

            catalog3.IsDeleted    = false;
            catalog3.Tenant_RefID = securityTicket.TenantID;
            catalog3.HEC_BIL_PotentialCode_CatalogID = Guid.NewGuid();
            catalog3.GlobalPropertyMatchingID        = "mm.docconnect.gpos.catalog.zusatzposition.bevacizumab";
            catalog3.Creation_Timestamp = DateTime.Now;
            catalog3.Save(Connection, Transaction);

            var catalog4 = new ORM_HEC_BIL_PotentialCode_Catalog();

            catalog4.IsDeleted    = false;
            catalog4.Tenant_RefID = securityTicket.TenantID;
            catalog4.HEC_BIL_PotentialCode_CatalogID = Guid.NewGuid();
            catalog4.GlobalPropertyMatchingID        = "mm.docconnect.gpos.catalog.wartezeitenmanagement";
            catalog4.Creation_Timestamp = DateTime.Now;
            catalog4.Save(Connection, Transaction);

            foreach (var partie in searchContractParties)
            {
                var searchContract = ORM_CMN_CTR_Contract.Query.Search(Connection, Transaction, new ORM_CMN_CTR_Contract.Query()
                {
                    IsDeleted          = false,
                    Tenant_RefID       = securityTicket.TenantID,
                    CMN_CTR_ContractID = partie.Contract_RefID,
                    ContractName       = "IVI-Vertrag",
                }).SingleOrDefault();
                if (searchContract != null)
                {
                    contractID = searchContract.CMN_CTR_ContractID;
                }
            }


            var hecContract = ORM_HEC_CRT_InsuranceToBrokerContract.Query.Search(Connection, Transaction, new ORM_HEC_CRT_InsuranceToBrokerContract.Query()
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID,
                Ext_CMN_CTR_Contract_RefID = contractID
            }).Single();

            foreach (var GPOSData in parameter)
            {
                var contract2BillCodes = new ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCode();
                contract2BillCodes.IsDeleted = false;
                contract2BillCodes.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID = Guid.NewGuid();
                contract2BillCodes.Tenant_RefID = securityTicket.TenantID;
                contract2BillCodes.InsuranceToBrokerContract_RefID = hecContract.HEC_CRT_InsuranceToBrokerContractID;
                contract2BillCodes.PotentialBillCode_RefID         = Guid.NewGuid();
                contract2BillCodes.Creation_Timestamp     = DateTime.Now;
                contract2BillCodes.Modification_Timestamp = DateTime.Now;
                contract2BillCodes.Save(Connection, Transaction);

                var  DBLanguages       = cls_Get_All_Languages.Invoke(Connection, Transaction, securityTicket).Result.ToList();
                Dict PotentialCodeName = new Dict(ORM_HEC_BIL_PotentialCode.TableName);
                for (int i = 0; i < DBLanguages.Count; i++)
                {
                    PotentialCodeName.AddEntry(DBLanguages[i].CMN_LanguageID, GPOSData.GPOSTitle);
                }

                Guid billCatalogID = Guid.NewGuid();
                switch (GPOSData.GPOSTitle)
                {
                case "Operation":
                    billCatalogID = catalog1.HEC_BIL_PotentialCode_CatalogID;
                    break;

                case "Nachsorge":
                    billCatalogID = catalog2.HEC_BIL_PotentialCode_CatalogID;
                    break;

                case "Zusatzposition Bevacizumab":
                    billCatalogID = catalog3.HEC_BIL_PotentialCode_CatalogID;
                    break;

                case "Wartezeitenmanagement":
                    billCatalogID = catalog4.HEC_BIL_PotentialCode_CatalogID;
                    break;
                }
                ;


                var potentialBillCode = new ORM_HEC_BIL_PotentialCode();
                potentialBillCode.IsDeleted               = false;
                potentialBillCode.Tenant_RefID            = securityTicket.TenantID;
                potentialBillCode.HEC_BIL_PotentialCodeID = contract2BillCodes.PotentialBillCode_RefID;
                potentialBillCode.Creation_Timestamp      = DateTime.Now;
                potentialBillCode.Modification_Timestamp  = DateTime.Now;
                potentialBillCode.CodeName    = PotentialCodeName;
                potentialBillCode.BillingCode = GPOSData.BillingCode;
                potentialBillCode.Price_RefID = Guid.NewGuid();
                potentialBillCode.PotentialCode_Catalog_RefID = billCatalogID;
                potentialBillCode.Save(Connection, Transaction);


                var hecBillCodes2UniversalProperty = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty();
                hecBillCodes2UniversalProperty.IsDeleted                      = false;
                hecBillCodes2UniversalProperty.Tenant_RefID                   = securityTicket.TenantID;
                hecBillCodes2UniversalProperty.Creation_Timestamp             = DateTime.Now;
                hecBillCodes2UniversalProperty.Modification_Timestamp         = DateTime.Now;
                hecBillCodes2UniversalProperty.AssignmentID                   = Guid.NewGuid();
                hecBillCodes2UniversalProperty.CoveredPotentialBillCode_RefID = contract2BillCodes.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID;
                hecBillCodes2UniversalProperty.CoveredPotentialBillCode_UniversalProperty_RefID = Guid.NewGuid();
                hecBillCodes2UniversalProperty.Value_String = GPOSData.Case_Type;
                hecBillCodes2UniversalProperty.Save(Connection, Transaction);

                var billCodesUniversalProperty = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty();
                billCodesUniversalProperty.IsDeleted              = false;
                billCodesUniversalProperty.Tenant_RefID           = securityTicket.TenantID;
                billCodesUniversalProperty.Creation_Timestamp     = DateTime.Now;
                billCodesUniversalProperty.Modification_Timestamp = DateTime.Now;
                billCodesUniversalProperty.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = hecBillCodes2UniversalProperty.CoveredPotentialBillCode_RefID;
                billCodesUniversalProperty.PropertyName   = GPOSData.Case_Type_Value;
                billCodesUniversalProperty.IsValue_Number = true;
                billCodesUniversalProperty.Save(Connection, Transaction);


                var hecBillCodes2UniversalProperty2 = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty();
                hecBillCodes2UniversalProperty2.IsDeleted                      = false;
                hecBillCodes2UniversalProperty2.Tenant_RefID                   = securityTicket.TenantID;
                hecBillCodes2UniversalProperty2.Creation_Timestamp             = DateTime.Now;
                hecBillCodes2UniversalProperty2.CoveredPotentialBillCode_RefID = contract2BillCodes.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID;
                hecBillCodes2UniversalProperty2.CoveredPotentialBillCode_UniversalProperty_RefID = Guid.NewGuid();
                hecBillCodes2UniversalProperty2.Value_Number = GPOSData.From_inj_No;
                hecBillCodes2UniversalProperty2.Save(Connection, Transaction);

                var billCodesUniversalProperty2 = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty();
                billCodesUniversalProperty2.IsDeleted              = false;
                billCodesUniversalProperty2.Tenant_RefID           = securityTicket.TenantID;
                billCodesUniversalProperty2.Creation_Timestamp     = DateTime.Now;
                billCodesUniversalProperty2.Modification_Timestamp = DateTime.Now;
                billCodesUniversalProperty2.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = hecBillCodes2UniversalProperty2.CoveredPotentialBillCode_UniversalProperty_RefID;
                billCodesUniversalProperty2.PropertyName   = GPOSData.From_inj;
                billCodesUniversalProperty2.IsValue_Number = true;
                billCodesUniversalProperty2.Save(Connection, Transaction);

                var hecBillCodes2UniversalProperty3 = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty();
                hecBillCodes2UniversalProperty3.IsDeleted                      = false;
                hecBillCodes2UniversalProperty3.Tenant_RefID                   = securityTicket.TenantID;
                hecBillCodes2UniversalProperty3.Creation_Timestamp             = DateTime.Now;
                hecBillCodes2UniversalProperty3.CoveredPotentialBillCode_RefID = contract2BillCodes.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID;
                hecBillCodes2UniversalProperty3.CoveredPotentialBillCode_UniversalProperty_RefID = Guid.NewGuid();
                hecBillCodes2UniversalProperty3.Value_Number = GPOSData.To_inj_No;
                hecBillCodes2UniversalProperty3.Save(Connection, Transaction);

                var billCodesUniversalProperty3 = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty();
                billCodesUniversalProperty3.IsDeleted              = false;
                billCodesUniversalProperty3.Tenant_RefID           = securityTicket.TenantID;
                billCodesUniversalProperty3.Creation_Timestamp     = DateTime.Now;
                billCodesUniversalProperty3.Modification_Timestamp = DateTime.Now;
                billCodesUniversalProperty3.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = hecBillCodes2UniversalProperty3.CoveredPotentialBillCode_UniversalProperty_RefID;
                billCodesUniversalProperty3.PropertyName   = GPOSData.To_inj;
                billCodesUniversalProperty3.IsValue_String = true;
                billCodesUniversalProperty3.Save(Connection, Transaction);

                var hecBillCodes2UniversalProperty4 = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty();
                hecBillCodes2UniversalProperty4.IsDeleted                      = false;
                hecBillCodes2UniversalProperty4.Tenant_RefID                   = securityTicket.TenantID;
                hecBillCodes2UniversalProperty4.Creation_Timestamp             = DateTime.Now;
                hecBillCodes2UniversalProperty4.CoveredPotentialBillCode_RefID = contract2BillCodes.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID;
                hecBillCodes2UniversalProperty4.CoveredPotentialBillCode_UniversalProperty_RefID = Guid.NewGuid();
                hecBillCodes2UniversalProperty4.Value_Boolean = GPOSData.Waive_with_Order_value;
                hecBillCodes2UniversalProperty4.Save(Connection, Transaction);

                var billCodesUniversalProperty4 = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty();
                billCodesUniversalProperty4.IsDeleted              = false;
                billCodesUniversalProperty4.Tenant_RefID           = securityTicket.TenantID;
                billCodesUniversalProperty4.Creation_Timestamp     = DateTime.Now;
                billCodesUniversalProperty4.Modification_Timestamp = DateTime.Now;
                billCodesUniversalProperty4.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = hecBillCodes2UniversalProperty4.CoveredPotentialBillCode_UniversalProperty_RefID;
                billCodesUniversalProperty4.PropertyName    = GPOSData.Waive_with_Order;
                billCodesUniversalProperty4.IsValue_Boolean = true;
                billCodesUniversalProperty4.Save(Connection, Transaction);



                var hecBillCodes2UniversalProperty5 = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty();
                hecBillCodes2UniversalProperty5.IsDeleted                      = false;
                hecBillCodes2UniversalProperty5.Tenant_RefID                   = securityTicket.TenantID;
                hecBillCodes2UniversalProperty5.Creation_Timestamp             = DateTime.Now;
                hecBillCodes2UniversalProperty5.CoveredPotentialBillCode_RefID = contract2BillCodes.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID;
                hecBillCodes2UniversalProperty5.CoveredPotentialBillCode_UniversalProperty_RefID = Guid.NewGuid();
                hecBillCodes2UniversalProperty5.Value_String = GPOSData.Service_fee_in_Eur_Value;
                hecBillCodes2UniversalProperty5.Save(Connection, Transaction);

                var billCodesUniversalProperty5 = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty();
                billCodesUniversalProperty5.IsDeleted              = false;
                billCodesUniversalProperty5.Tenant_RefID           = securityTicket.TenantID;
                billCodesUniversalProperty5.Creation_Timestamp     = DateTime.Now;
                billCodesUniversalProperty5.Modification_Timestamp = DateTime.Now;
                billCodesUniversalProperty5.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = hecBillCodes2UniversalProperty5.CoveredPotentialBillCode_UniversalProperty_RefID;
                billCodesUniversalProperty5.PropertyName   = GPOSData.Service_fee_in_Eur;
                billCodesUniversalProperty5.IsValue_String = true;
                billCodesUniversalProperty5.Save(Connection, Transaction);



                var currencyforTenant = ORM_CMN_Currency.Query.Search(Connection, Transaction, new ORM_CMN_Currency.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).First();

                var price = new ORM_CMN_Price();
                price.CMN_PriceID        = potentialBillCode.Price_RefID;
                price.IsDeleted          = false;
                price.Tenant_RefID       = securityTicket.TenantID;
                price.Creation_Timestamp = DateTime.Now;
                price.Save(Connection, Transaction);

                var priceValue = new ORM_CMN_Price_Value();
                priceValue.CMN_Price_ValueID         = Guid.NewGuid();
                priceValue.IsDeleted                 = false;
                priceValue.Tenant_RefID              = securityTicket.TenantID;
                priceValue.Price_RefID               = price.CMN_PriceID;
                priceValue.PriceValue_Amount         = GPOSData.Fee_in_EUR;
                priceValue.PriceValue_Currency_RefID = currencyforTenant.CMN_CurrencyID;
                priceValue.Save(Connection, Transaction);


                var hecContract2Diagnosis = ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialDiagnosis.Query.Search(Connection, Transaction, new ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialDiagnosis.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    InsuranceToBrokerContract_RefID = hecContract.HEC_CRT_InsuranceToBrokerContractID
                }).ToList();
                List <ORM_HEC_DIA_PotentialDiagnosis> potendialDiagnosisList = new List <ORM_HEC_DIA_PotentialDiagnosis>();
                foreach (var ctr2dia in hecContract2Diagnosis)
                {
                    var potentialDiagnosis = ORM_HEC_DIA_PotentialDiagnosis.Query.Search(Connection, Transaction, new ORM_HEC_DIA_PotentialDiagnosis.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        HEC_DIA_PotentialDiagnosisID = ctr2dia.PotentialDiagnosis_RefID
                    }).SingleOrDefault();
                    potendialDiagnosisList.Add(potentialDiagnosis);
                }

                foreach (var diagnosispot in potendialDiagnosisList)
                {
                    foreach (var diagnosisData in GPOSData.DiagnosisForGPOS)
                    {
                        var CatalogCodes = ORM_HEC_DIA_PotentialDiagnosis_CatalogCode.Query.Search(Connection, Transaction, new ORM_HEC_DIA_PotentialDiagnosis_CatalogCode.Query()
                        {
                            IsDeleted                = false,
                            Tenant_RefID             = securityTicket.TenantID,
                            PotentialDiagnosis_RefID = diagnosispot.HEC_DIA_PotentialDiagnosisID
                        }).SingleOrDefault();
                        if (CatalogCodes.Code != null)
                        {
                            if (CatalogCodes.Code == diagnosisData.DiagnoseCode || diagnosisData.DiagnoseCode == "all")
                            {
                                var BillCode2PotentialDiagnosis = new ORM_HEC_BIL_PotentialCode_2_PotentialDiagnosis();
                                BillCode2PotentialDiagnosis.HEC_BIL_PotentialCode_RefID      = potentialBillCode.HEC_BIL_PotentialCodeID;
                                BillCode2PotentialDiagnosis.HEC_DIA_PotentialDiagnosis_RefID = diagnosispot.HEC_DIA_PotentialDiagnosisID;
                                BillCode2PotentialDiagnosis.IsDeleted              = false;
                                BillCode2PotentialDiagnosis.Tenant_RefID           = securityTicket.TenantID;
                                BillCode2PotentialDiagnosis.Creation_Timestamp     = DateTime.Now;
                                BillCode2PotentialDiagnosis.Modification_Timestamp = DateTime.Now;
                                BillCode2PotentialDiagnosis.Save(Connection, Transaction);
                            }
                        }
                    }
                }

                var hecContract2Products = ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredHealthcareProduct.Query.Search(Connection, Transaction, new ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredHealthcareProduct.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    InsuranceToBrokerContract_RefID = hecContract.HEC_CRT_InsuranceToBrokerContractID
                }).ToList();

                List <ORM_HEC_Product> HecProductList = new List <ORM_HEC_Product>();
                foreach (var cont2product in hecContract2Products)
                {
                    var searchProducts = ORM_HEC_Product.Query.Search(Connection, Transaction, new ORM_HEC_Product.Query()
                    {
                        IsDeleted     = false,
                        Tenant_RefID  = securityTicket.TenantID,
                        HEC_ProductID = cont2product.HealthcareProduct_RefID
                    }).SingleOrDefault();
                    if (searchProducts != null)
                    {
                        HecProductList.Add(searchProducts);
                    }
                }

                List <ORM_CMN_PRO_Product> drugList = new List <ORM_CMN_PRO_Product>();
                foreach (var hecProd in HecProductList)
                {
                    var searchProd = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product.Query()
                    {
                        IsDeleted         = false,
                        Tenant_RefID      = securityTicket.TenantID,
                        CMN_PRO_ProductID = hecProd.Ext_PRO_Product_RefID
                    }).SingleOrDefault();
                    if (searchProd != null)
                    {
                        drugList.Add(searchProd);
                    }
                }



                if (GPOSData.DrugsForGPOS != null)
                {
                    foreach (var drugsData in GPOSData.DrugsForGPOS)
                    {
                        foreach (var drug in HecProductList)
                        {
                            Dict ProductNameDict = new Dict(ORM_CMN_PRO_Product.TableName);
                            for (int i = 0; i < DBLanguages.Count; i++)
                            {
                                ProductNameDict.AddEntry(DBLanguages[i].CMN_LanguageID, drugsData.Drug_name);
                            }

                            var searchProd = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product.Query()
                            {
                                IsDeleted         = false,
                                Tenant_RefID      = securityTicket.TenantID,
                                CMN_PRO_ProductID = drug.Ext_PRO_Product_RefID
                            }).SingleOrDefault();

                            if (searchProd.Product_Name.Contents[0].Content == ProductNameDict.Contents[0].Content || drugsData.Drug_name == "all")
                            {
                                var billCode2product = new ORM_HEC_BIL_PotentialCode_2_HealthcareProduct();
                                billCode2product.IsDeleted                   = false;
                                billCode2product.Tenant_RefID                = securityTicket.TenantID;
                                billCode2product.Creation_Timestamp          = DateTime.Now;
                                billCode2product.AssignmentID                = Guid.NewGuid();
                                billCode2product.HEC_BIL_PotentialCode_RefID = potentialBillCode.HEC_BIL_PotentialCodeID;
                                billCode2product.HEC_Product_RefID           = drug.HEC_ProductID;
                                billCode2product.Save(Connection, Transaction);
                            }
                        }
                    }
                }

                else
                {
                    Console.WriteLine(GPOSData);
                }
            }
        }
Пример #3
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5AT_SA_1301 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            ORM_RES_ACT_Action_Version oldVersion = new ORM_RES_ACT_Action_Version();
            ORM_RES_ACT_Action         action     = new ORM_RES_ACT_Action();
            int versionNumber = 0;
            if (Parameter.RES_ACT_ActionID != Guid.Empty)
            {
                var result = action.Load(Connection, Transaction, Parameter.RES_ACT_ActionID);
                if (result.Status != FR_Status.Success || action.RES_ACT_ActionID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                ORM_RES_ACT_Action_Version.Query versionQuery = new ORM_RES_ACT_Action_Version.Query();
                versionQuery.Tenant_RefID = securityTicket.TenantID;
                versionQuery.IsDeleted    = false;
                versionQuery.Action_RefID = action.RES_ACT_ActionID;
                List <ORM_RES_ACT_Action_Version> versions = ORM_RES_ACT_Action_Version.Query.Search(Connection, Transaction, versionQuery);

                action.RES_ACT_ActionID = Parameter.RES_ACT_ActionID;
                versionNumber           = versions.Max(i => i.Action_Version);
                oldVersion = versions.FirstOrDefault(i => i.Action_Version == versionNumber);
                versionNumber++;
            }
            else
            {
                versionNumber       = 1;
                action.Tenant_RefID = securityTicket.TenantID;
            }

            action.ActionType_RefID = Parameter.ActionType_RefID;


            ORM_CMN_Price price = new ORM_CMN_Price();
            if (Parameter.Default_PricePerUnit_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.Default_PricePerUnit_RefID);
                if (result.Status != FR_Status.Success || action.RES_ACT_ActionID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ORM_CMN_Price_Value.Query priceQuery = new ORM_CMN_Price_Value.Query();
            priceQuery.Tenant_RefID = securityTicket.TenantID;
            priceQuery.Price_RefID  = price.CMN_PriceID;
            priceQuery.IsDeleted    = false;
            List <ORM_CMN_Price_Value> priceValueList = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceQuery);

            ORM_CMN_Price_Value priceValue = new ORM_CMN_Price_Value();
            if (priceValueList.Count != 0)
            {
                priceValue.Load(Connection, Transaction, priceValueList[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.Default_PricePerUnit;
            priceValue.Save(Connection, Transaction);


            ORM_RES_ACT_Action_Version version = new ORM_RES_ACT_Action_Version();
            version.Action_Description         = Parameter.Action_Description_DictID;
            version.Action_Name                = Parameter.Action_Name_DictID;
            version.Action_RefID               = action.RES_ACT_ActionID;
            version.Action_Version             = Parameter.Action_Version;
            version.Default_PricePerUnit_RefID = price.CMN_PriceID;
            version.Default_Unit_RefID         = Parameter.Default_Unit_RefID;
            version.Default_UnitAmount         = Parameter.Default_UnitAmount;
            version.Tenant_RefID               = securityTicket.TenantID;
            version.Action_Version             = versionNumber;
            version.Save(Connection, Transaction);

            action.CurrentVersion_RefID = version.RES_ACT_Action_VersionID;
            action.Save(Connection, Transaction);

            if (Parameter.RES_ACT_ActionID != Guid.Empty)
            {
                ORM_RES_STR_OutdoorFacility_Property_AvailableAction.Query query1 = new ORM_RES_STR_OutdoorFacility_Property_AvailableAction.Query();
                query1.RES_ACT_Action_RefID = Parameter.RES_ACT_ActionID;
                ORM_RES_STR_OutdoorFacility_Property_AvailableAction.Query.SoftDelete(Connection, Transaction, query1);

                ORM_RES_STR_Facade_Property_AvailableAction.Query query2 = new ORM_RES_STR_Facade_Property_AvailableAction.Query();
                query2.RES_ACT_Action_RefID = Parameter.RES_ACT_ActionID;
                ORM_RES_STR_Facade_Property_AvailableAction.Query.SoftDelete(Connection, Transaction, query2);

                ORM_RES_STR_Roof_Property_AvailableAction.Query query3 = new ORM_RES_STR_Roof_Property_AvailableAction.Query();
                query3.RES_ACT_Action_RefID = Parameter.RES_ACT_ActionID;
                ORM_RES_STR_Roof_Property_AvailableAction.Query.SoftDelete(Connection, Transaction, query3);

                ORM_RES_STR_Attic_Property_AvailableAction.Query query4 = new ORM_RES_STR_Attic_Property_AvailableAction.Query();
                query4.RES_ACT_Action_RefID = Parameter.RES_ACT_ActionID;
                ORM_RES_STR_Attic_Property_AvailableAction.Query.SoftDelete(Connection, Transaction, query4);

                ORM_RES_STR_Staircase_Property_AvailableAction.Query query5 = new ORM_RES_STR_Staircase_Property_AvailableAction.Query();
                query5.RES_ACT_Action_RefID = Parameter.RES_ACT_ActionID;
                ORM_RES_STR_Staircase_Property_AvailableAction.Query.SoftDelete(Connection, Transaction, query5);

                ORM_RES_STR_Basement_Property_AvailableAction.Query query6 = new ORM_RES_STR_Basement_Property_AvailableAction.Query();
                query6.RES_ACT_Action_RefID = Parameter.RES_ACT_ActionID;
                ORM_RES_STR_Basement_Property_AvailableAction.Query.SoftDelete(Connection, Transaction, query6);

                ORM_RES_STR_HVACR_Property_AvailableAction.Query query7 = new ORM_RES_STR_HVACR_Property_AvailableAction.Query();
                query7.RES_ACT_Action_RefID = Parameter.RES_ACT_ActionID;
                ORM_RES_STR_HVACR_Property_AvailableAction.Query.SoftDelete(Connection, Transaction, query7);

                ORM_RES_STR_Apartment_Property_AvailableAction.Query query8 = new ORM_RES_STR_Apartment_Property_AvailableAction.Query();
                query8.RES_ACT_Action_RefID = Parameter.RES_ACT_ActionID;
                ORM_RES_STR_Apartment_Property_AvailableAction.Query.SoftDelete(Connection, Transaction, query8);
            }

            if (Parameter.availableQuestions != null)
            {
                foreach (var question in Parameter.availableQuestions)
                {
                    if (question.questionType == "OutdoorFacility")
                    {
                        ORM_RES_STR_OutdoorFacility_Property_AvailableAction item = new ORM_RES_STR_OutdoorFacility_Property_AvailableAction();
                        item.RES_STR_OutdoorFacility_Property_RefID = question.questionID;
                        item.RES_ACT_Action_RefID = action.RES_ACT_ActionID;
                        item.Tenant_RefID         = securityTicket.TenantID;
                        item.Save(Connection, Transaction);
                    }

                    if (question.questionType == "Facade")
                    {
                        ORM_RES_STR_Facade_Property_AvailableAction item = new ORM_RES_STR_Facade_Property_AvailableAction();
                        item.RES_STR_Facade_Property_RefID = question.questionID;
                        item.RES_ACT_Action_RefID          = action.RES_ACT_ActionID;
                        item.Tenant_RefID = securityTicket.TenantID;
                        item.Save(Connection, Transaction);
                    }

                    if (question.questionType == "Roof")
                    {
                        ORM_RES_STR_Roof_Property_AvailableAction item = new ORM_RES_STR_Roof_Property_AvailableAction();
                        item.RES_STR_Roof_Property_RefID = question.questionID;
                        item.RES_ACT_Action_RefID        = action.RES_ACT_ActionID;
                        item.Tenant_RefID = securityTicket.TenantID;
                        item.Save(Connection, Transaction);
                    }

                    if (question.questionType == "Attic")
                    {
                        ORM_RES_STR_Attic_Property_AvailableAction item = new ORM_RES_STR_Attic_Property_AvailableAction();
                        item.RES_STR_Attic_Property_RefID = question.questionID;
                        item.RES_ACT_Action_RefID         = action.RES_ACT_ActionID;
                        item.Tenant_RefID = securityTicket.TenantID;
                        item.Save(Connection, Transaction);
                    }

                    if (question.questionType == "Staircase")
                    {
                        ORM_RES_STR_Staircase_Property_AvailableAction item = new ORM_RES_STR_Staircase_Property_AvailableAction();
                        item.RES_STR_Staircase_Property_RefID = question.questionID;
                        item.RES_ACT_Action_RefID             = action.RES_ACT_ActionID;
                        item.Tenant_RefID = securityTicket.TenantID;
                        item.Save(Connection, Transaction);
                    }

                    if (question.questionType == "Basement")
                    {
                        ORM_RES_STR_Basement_Property_AvailableAction item = new ORM_RES_STR_Basement_Property_AvailableAction();
                        item.RES_STR_Basement_Property_RefID = question.questionID;
                        item.RES_ACT_Action_RefID            = action.RES_ACT_ActionID;
                        item.Tenant_RefID = securityTicket.TenantID;
                        item.Save(Connection, Transaction);
                    }

                    if (question.questionType == "HVCAR")
                    {
                        ORM_RES_STR_HVACR_Property_AvailableAction item = new ORM_RES_STR_HVACR_Property_AvailableAction();
                        item.RES_STR_HVACR_Property_RefID = question.questionID;
                        item.RES_ACT_Action_RefID         = action.RES_ACT_ActionID;
                        item.Tenant_RefID = securityTicket.TenantID;
                        item.Save(Connection, Transaction);
                    }

                    if (question.questionType == "Apartment")
                    {
                        ORM_RES_STR_Apartment_Property_AvailableAction item = new ORM_RES_STR_Apartment_Property_AvailableAction();
                        item.RES_STR_Apartment_Property_RefID = question.questionID;
                        item.RES_ACT_Action_RefID             = action.RES_ACT_ActionID;
                        item.Tenant_RefID = securityTicket.TenantID;
                        item.Save(Connection, Transaction);
                    }
                }
            }


            returnValue.Result = action.RES_ACT_ActionID;
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_MD_SCGPOSD_1306 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            var insuranceToBrokerContract = ORM_HEC_CRT_InsuranceToBrokerContract.Query.Search(Connection, Transaction, new ORM_HEC_CRT_InsuranceToBrokerContract.Query()
            {
                Ext_CMN_CTR_Contract_RefID = Parameter.ContractID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (insuranceToBrokerContract == null)
            {
                insuranceToBrokerContract = new ORM_HEC_CRT_InsuranceToBrokerContract();
                insuranceToBrokerContract.Creation_Timestamp                  = DateTime.Now;
                insuranceToBrokerContract.Ext_CMN_CTR_Contract_RefID          = Parameter.ContractID;
                insuranceToBrokerContract.HEC_CRT_InsuranceToBrokerContractID = Guid.NewGuid();
                insuranceToBrokerContract.Modification_Timestamp              = DateTime.Now;
                insuranceToBrokerContract.Tenant_RefID = securityTicket.TenantID;

                insuranceToBrokerContract.Save(Connection, Transaction);
            }

            var allLanguages = ORM_CMN_Language.Query.Search(Connection, Transaction, new ORM_CMN_Language.Query()
            {
                Tenant_RefID = securityTicket.TenantID, IsDeleted = false
            }).ToArray();

            var currency = ORM_CMN_Currency.Query.Search(Connection, Transaction, new ORM_CMN_Currency.Query()
            {
                ISO4127 = "EUR", IsDeleted = false, Symbol = "EUR", Tenant_RefID = securityTicket.TenantID
            }).Single();

            #region DELETE DISCONNECTED GPOS-ES
            var currentGposesConnectedToContract = ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCode.Query.Search(Connection, Transaction, new ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCode.Query()
            {
                InsuranceToBrokerContract_RefID = insuranceToBrokerContract.HEC_CRT_InsuranceToBrokerContractID,
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            });
            var gposIDs = Parameter.GposData.Select(gpos => gpos.GposID).ToArray();

            foreach (var currGpos in currentGposesConnectedToContract)
            {
                var exists = gposIDs.Any(id => currGpos.PotentialBillCode_RefID == id);
                if (!gposIDs.Any(id => id == currGpos.PotentialBillCode_RefID))
                {
                    cls_Delete_GPOS_Data.Invoke(Connection, Transaction, new P_MD_DGPOSD_1033()
                    {
                        GposID = currGpos.PotentialBillCode_RefID
                    }, securityTicket);
                }
            }
            #endregion DELETE DISCONNECTED GPOS-ES

            foreach (var gpos in Parameter.GposData)
            {
                #region NEW GPOS DATA
                if (gpos.GposID == Guid.Empty)
                {
                    #region GPOS CATALOG
                    var catalog = ORM_HEC_BIL_PotentialCode_Catalog.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode_Catalog.Query()
                    {
                        GlobalPropertyMatchingID = gpos.GposType,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).SingleOrDefault();

                    if (catalog == null)
                    {
                        catalog = new ORM_HEC_BIL_PotentialCode_Catalog();
                        var catalogNameDict   = new Dict(ORM_HEC_BIL_PotentialCode_Catalog.TableName);
                        var catalogNameString = gpos.GposType.Replace("mm.docconnect.gpos.catalog.", "");
                        catalogNameString = catalogNameString.Substring(0, 1).ToUpper() + catalogNameString.Substring(1);
                        foreach (var lang in allLanguages)
                        {
                            catalogNameDict.AddEntry(lang.CMN_LanguageID, catalogNameString);
                        }
                        catalog.GlobalPropertyMatchingID = gpos.GposType;
                        catalog.Modification_Timestamp   = DateTime.Now;
                        catalog.Tenant_RefID             = securityTicket.TenantID;

                        catalog.Save(Connection, Transaction);
                    }
                    #endregion GPOS CATALOG

                    #region PRICE
                    var price = new ORM_CMN_Price();
                    price.CMN_PriceID        = Guid.NewGuid();
                    price.Creation_Timestamp = DateTime.Now;
                    price.Tenant_RefID       = securityTicket.TenantID;

                    price.Save(Connection, Transaction);

                    var priceValue = new ORM_CMN_Price_Value();
                    priceValue.CMN_Price_ValueID         = Guid.NewGuid();
                    priceValue.Creation_Timestamp        = DateTime.Now;
                    priceValue.Price_RefID               = price.CMN_PriceID;
                    priceValue.PriceValue_Amount         = gpos.FeeValue;
                    priceValue.PriceValue_Currency_RefID = currency.CMN_CurrencyID;
                    priceValue.Tenant_RefID              = securityTicket.TenantID;

                    priceValue.Save(Connection, Transaction);
                    #endregion PRICE

                    #region POTENTIAL CODE
                    var newPotentialCode = new ORM_HEC_BIL_PotentialCode();

                    var potentialCodeName = new Dict(ORM_HEC_BIL_PotentialCode.TableName);
                    foreach (var lang in allLanguages)
                    {
                        potentialCodeName.AddEntry(lang.CMN_LanguageID, gpos.GposName);
                    }

                    newPotentialCode.CodeName                    = potentialCodeName;
                    newPotentialCode.Creation_Timestamp          = DateTime.Now;
                    newPotentialCode.HEC_BIL_PotentialCodeID     = Guid.NewGuid();
                    newPotentialCode.PotentialCode_Catalog_RefID = catalog.HEC_BIL_PotentialCode_CatalogID;
                    newPotentialCode.Modification_Timestamp      = DateTime.Now;
                    newPotentialCode.Price_RefID                 = price.CMN_PriceID;
                    newPotentialCode.BillingCode                 = gpos.GposNumber;
                    newPotentialCode.Tenant_RefID                = securityTicket.TenantID;

                    newPotentialCode.Save(Connection, Transaction);
                    #endregion POTENTIAL CODE

                    #region CONTRACT CONNECTION

                    var coveredPotentialCode = new ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCode();
                    coveredPotentialCode.Creation_Timestamp = DateTime.Now;
                    coveredPotentialCode.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID = Guid.NewGuid();
                    coveredPotentialCode.InsuranceToBrokerContract_RefID = insuranceToBrokerContract.HEC_CRT_InsuranceToBrokerContractID;
                    coveredPotentialCode.Modification_Timestamp          = DateTime.Now;
                    coveredPotentialCode.PotentialBillCode_RefID         = newPotentialCode.HEC_BIL_PotentialCodeID;
                    coveredPotentialCode.Tenant_RefID = securityTicket.TenantID;

                    coveredPotentialCode.Save(Connection, Transaction);

                    #endregion CONTRACT CONNECTION

                    #region POTENTIAL CODE PROPERTIES

                    #region FROM INJECTION
                    var fromInjectionProperty = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty();
                    fromInjectionProperty.Creation_Timestamp = DateTime.Now;
                    fromInjectionProperty.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = Guid.NewGuid();
                    fromInjectionProperty.IsValue_Number         = true;
                    fromInjectionProperty.Modification_Timestamp = DateTime.Now;
                    fromInjectionProperty.PropertyName           = "From injection no.";
                    fromInjectionProperty.Tenant_RefID           = securityTicket.TenantID;

                    fromInjectionProperty.Save(Connection, Transaction);

                    var fromInjectionPropertyToCode = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty();
                    fromInjectionPropertyToCode.Tenant_RefID = securityTicket.TenantID;
                    fromInjectionPropertyToCode.AssignmentID = Guid.NewGuid();
                    fromInjectionPropertyToCode.CoveredPotentialBillCode_RefID = coveredPotentialCode.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID;
                    fromInjectionPropertyToCode.CoveredPotentialBillCode_UniversalProperty_RefID = fromInjectionProperty.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID;
                    fromInjectionPropertyToCode.Creation_Timestamp     = DateTime.Now;
                    fromInjectionPropertyToCode.Modification_Timestamp = DateTime.Now;
                    fromInjectionPropertyToCode.Value_Number           = gpos.FromInjection == 0 || gpos.FromInjection == null ? int.MaxValue : gpos.FromInjection;

                    fromInjectionPropertyToCode.Save(Connection, Transaction);
                    #endregion FROM INJECTION

                    #region SERVICE FEE
                    var serviceFeeProperty = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty();
                    serviceFeeProperty.Creation_Timestamp = DateTime.Now;
                    serviceFeeProperty.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = Guid.NewGuid();
                    serviceFeeProperty.IsValue_String         = true;
                    serviceFeeProperty.Modification_Timestamp = DateTime.Now;
                    serviceFeeProperty.PropertyName           = "Service Fee in EUR";
                    serviceFeeProperty.Tenant_RefID           = securityTicket.TenantID;

                    serviceFeeProperty.Save(Connection, Transaction);

                    var serviceFeePropertyToCode = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty();
                    serviceFeePropertyToCode.Tenant_RefID = securityTicket.TenantID;
                    serviceFeePropertyToCode.AssignmentID = Guid.NewGuid();
                    serviceFeePropertyToCode.CoveredPotentialBillCode_RefID = coveredPotentialCode.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID;
                    serviceFeePropertyToCode.CoveredPotentialBillCode_UniversalProperty_RefID = serviceFeeProperty.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID;
                    serviceFeePropertyToCode.Creation_Timestamp     = DateTime.Now;
                    serviceFeePropertyToCode.Modification_Timestamp = DateTime.Now;
                    serviceFeePropertyToCode.Value_String           = string.IsNullOrEmpty(gpos.ManagementFeeValue) ? "-" : gpos.ManagementFeeValue;

                    serviceFeePropertyToCode.Save(Connection, Transaction);
                    #endregion SERVICE FEE

                    #region WAIVE WITH ORDER
                    var waiveWithOrderProperty = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty();
                    waiveWithOrderProperty.Creation_Timestamp = DateTime.Now;
                    waiveWithOrderProperty.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = Guid.NewGuid();
                    waiveWithOrderProperty.IsValue_Boolean        = true;
                    waiveWithOrderProperty.Modification_Timestamp = DateTime.Now;
                    waiveWithOrderProperty.PropertyName           = "Waive with order";
                    waiveWithOrderProperty.Tenant_RefID           = securityTicket.TenantID;

                    waiveWithOrderProperty.Save(Connection, Transaction);

                    var waiveWithOrderPropertyToCode = new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty();
                    waiveWithOrderPropertyToCode.Tenant_RefID = securityTicket.TenantID;
                    waiveWithOrderPropertyToCode.AssignmentID = Guid.NewGuid();
                    waiveWithOrderPropertyToCode.CoveredPotentialBillCode_RefID = coveredPotentialCode.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID;
                    waiveWithOrderPropertyToCode.CoveredPotentialBillCode_UniversalProperty_RefID = waiveWithOrderProperty.HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID;
                    waiveWithOrderPropertyToCode.Creation_Timestamp     = DateTime.Now;
                    waiveWithOrderPropertyToCode.Modification_Timestamp = DateTime.Now;
                    waiveWithOrderPropertyToCode.Value_Boolean          = gpos.WaiveServiceFeeWithOrder;

                    waiveWithOrderPropertyToCode.Save(Connection, Transaction);
                    #endregion WAIVE WITH ORDER

                    #endregion POTENTIAL CODE PROPERTIES

                    #region CONNECTED DRUGS
                    if (gpos.DrugIDs.Length != 0)
                    {
                        foreach (var drugID in gpos.DrugIDs)
                        {
                            var potentialCodeToDrug = new ORM_HEC_BIL_PotentialCode_2_HealthcareProduct();
                            potentialCodeToDrug.AssignmentID                = Guid.NewGuid();
                            potentialCodeToDrug.Creation_Timestamp          = DateTime.Now;
                            potentialCodeToDrug.HEC_BIL_PotentialCode_RefID = newPotentialCode.HEC_BIL_PotentialCodeID;
                            potentialCodeToDrug.HEC_Product_RefID           = drugID;
                            potentialCodeToDrug.Modification_Timestamp      = DateTime.Now;
                            potentialCodeToDrug.Tenant_RefID                = securityTicket.TenantID;

                            potentialCodeToDrug.Save(Connection, Transaction);
                        }
                    }
                    #endregion CONNECTED DRUGS

                    #region CONNECTED DIAGNOSES
                    if (gpos.DiagnoseIDs.Length != 0)
                    {
                        foreach (var diagnoseID in gpos.DiagnoseIDs)
                        {
                            var potentialCodeToDiagnose = new ORM_HEC_BIL_PotentialCode_2_PotentialDiagnosis();
                            potentialCodeToDiagnose.AssignmentID                     = Guid.NewGuid();
                            potentialCodeToDiagnose.Creation_Timestamp               = DateTime.Now;
                            potentialCodeToDiagnose.HEC_BIL_PotentialCode_RefID      = newPotentialCode.HEC_BIL_PotentialCodeID;
                            potentialCodeToDiagnose.HEC_DIA_PotentialDiagnosis_RefID = diagnoseID;
                            potentialCodeToDiagnose.Modification_Timestamp           = DateTime.Now;
                            potentialCodeToDiagnose.Tenant_RefID                     = securityTicket.TenantID;

                            potentialCodeToDiagnose.Save(Connection, Transaction);
                        }
                    }
                    #endregion CONNECTED DIAGNOSES
                }
                #endregion NEW GPOS DATA

                #region EDIT
                else
                {
                    var currentGpos = ORM_HEC_BIL_PotentialCode.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode.Query()
                    {
                        HEC_BIL_PotentialCodeID = gpos.GposID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).SingleOrDefault();
                    if (currentGpos != null)
                    {
                        #region BASE DATA
                        var potentialCodeName = new Dict(ORM_HEC_BIL_PotentialCode.TableName);
                        foreach (var lang in allLanguages)
                        {
                            potentialCodeName.AddEntry(lang.CMN_LanguageID, gpos.GposName);
                        }
                        currentGpos.CodeName    = potentialCodeName;
                        currentGpos.BillingCode = gpos.GposNumber;

                        var catalog = ORM_HEC_BIL_PotentialCode_Catalog.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode_Catalog.Query()
                        {
                            GlobalPropertyMatchingID = gpos.GposType,
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID
                        }).SingleOrDefault();

                        if (catalog == null)
                        {
                            catalog = new ORM_HEC_BIL_PotentialCode_Catalog();
                            var catalogNameDict   = new Dict(ORM_HEC_BIL_PotentialCode_Catalog.TableName);
                            var catalogNameString = gpos.GposType.Replace("mm.docconnect.gpos.catalog.", "");
                            catalogNameString = catalogNameString.Substring(0, 1).ToUpper() + catalogNameString.Substring(1);

                            foreach (var lang in allLanguages)
                            {
                                catalogNameDict.AddEntry(lang.CMN_LanguageID, catalogNameString);
                            }

                            catalog.GlobalPropertyMatchingID = gpos.GposType;
                            catalog.Modification_Timestamp   = DateTime.Now;
                            catalog.Tenant_RefID             = securityTicket.TenantID;

                            catalog.Save(Connection, Transaction);
                        }

                        currentGpos.PotentialCode_Catalog_RefID = catalog.HEC_BIL_PotentialCode_CatalogID;

                        currentGpos.Save(Connection, Transaction);
                        #endregion

                        #region PRICE
                        var currentPriceValue = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, new ORM_CMN_Price_Value.Query()
                        {
                            Tenant_RefID = securityTicket.TenantID,
                            IsDeleted    = false,
                            Price_RefID  = currentGpos.Price_RefID
                        }).SingleOrDefault();

                        if (currentPriceValue != null)
                        {
                            currentPriceValue.PriceValue_Amount = gpos.FeeValue;
                            currentPriceValue.Save(Connection, Transaction);
                        }
                        #endregion

                        #region CONTRACT CONNECTION
                        var coveredPotentialCode = ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCode.Query.Search(Connection, Transaction, new ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCode.Query()
                        {
                            PotentialBillCode_RefID = gpos.GposID,
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID
                        }).SingleOrDefault();
                        #endregion

                        #region POTENTIAL CODE PROPERTIES
                        var gposPropertyConnections = ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_2_UniversalProperty.Query()
                        {
                            CoveredPotentialBillCode_RefID = coveredPotentialCode.HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCodeID,
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID
                        });

                        foreach (var conn in gposPropertyConnections)
                        {
                            var gposProperty = ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalProperty.Query()
                            {
                                HEC_CTR_I2BC_CoveredPotentialBillCodes_UniversalPropertyID = conn.CoveredPotentialBillCode_UniversalProperty_RefID,
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID
                            }).SingleOrDefault();

                            if (gposProperty != null)
                            {
                                switch (gposProperty.PropertyName)
                                {
                                case "From injection no.":
                                    conn.Value_Number = gpos.FromInjection;
                                    break;

                                case "Waive with order":
                                    conn.Value_Boolean = gpos.WaiveServiceFeeWithOrder;
                                    break;

                                case "Service Fee in EUR":
                                    conn.Value_String = gpos.ManagementFeeValue;
                                    break;
                                }

                                conn.Modification_Timestamp = DateTime.Now;
                                conn.Save(Connection, Transaction);
                            }
                        }

                        #endregion POTENTIAL CODE PROPERTIES

                        #region CONNECTED DRUGS
                        var currentGposDrugConnections = ORM_HEC_BIL_PotentialCode_2_HealthcareProduct.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode_2_HealthcareProduct.Query()
                        {
                            HEC_BIL_PotentialCode_RefID = gpos.GposID,
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID
                        });

                        foreach (var drugConnection in currentGposDrugConnections)
                        {
                            if (gpos.DrugIDs.Length == 0 || !gpos.DrugIDs.Any(did => did == drugConnection.HEC_Product_RefID))
                            {
                                drugConnection.IsDeleted = true;
                                drugConnection.Modification_Timestamp = DateTime.Now;

                                drugConnection.Save(Connection, Transaction);
                            }
                        }

                        foreach (var drugID in gpos.DrugIDs)
                        {
                            if (!currentGposDrugConnections.Any(cpd => cpd.HEC_Product_RefID == drugID))
                            {
                                var newDrugConnection = new ORM_HEC_BIL_PotentialCode_2_HealthcareProduct();
                                newDrugConnection.AssignmentID                = Guid.NewGuid();
                                newDrugConnection.Creation_Timestamp          = DateTime.Now;
                                newDrugConnection.HEC_BIL_PotentialCode_RefID = gpos.GposID;
                                newDrugConnection.HEC_Product_RefID           = drugID;
                                newDrugConnection.Modification_Timestamp      = DateTime.Now;
                                newDrugConnection.Tenant_RefID                = securityTicket.TenantID;

                                newDrugConnection.Save(Connection, Transaction);
                            }
                        }

                        #endregion CONNECTED DRUGS

                        #region CONNECTED DIAGNOSES
                        var currentGposDiagnoseConnections = ORM_HEC_BIL_PotentialCode_2_PotentialDiagnosis.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode_2_PotentialDiagnosis.Query()
                        {
                            HEC_BIL_PotentialCode_RefID = gpos.GposID,
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID
                        });

                        foreach (var diagnoseConnection in currentGposDiagnoseConnections)
                        {
                            if (gpos.DiagnoseIDs.Length == 0 || !gpos.DiagnoseIDs.Any(did => did == diagnoseConnection.HEC_DIA_PotentialDiagnosis_RefID))
                            {
                                diagnoseConnection.IsDeleted = true;
                                diagnoseConnection.Modification_Timestamp = DateTime.Now;

                                diagnoseConnection.Save(Connection, Transaction);
                            }
                        }

                        foreach (var diagnoseID in gpos.DiagnoseIDs)
                        {
                            if (!currentGposDiagnoseConnections.Any(cpd => cpd.HEC_DIA_PotentialDiagnosis_RefID == diagnoseID))
                            {
                                var newDiagnoseConnection = new ORM_HEC_BIL_PotentialCode_2_PotentialDiagnosis();
                                newDiagnoseConnection.AssignmentID                     = Guid.NewGuid();
                                newDiagnoseConnection.Creation_Timestamp               = DateTime.Now;
                                newDiagnoseConnection.HEC_BIL_PotentialCode_RefID      = gpos.GposID;
                                newDiagnoseConnection.HEC_DIA_PotentialDiagnosis_RefID = diagnoseID;
                                newDiagnoseConnection.Modification_Timestamp           = DateTime.Now;
                                newDiagnoseConnection.Tenant_RefID                     = securityTicket.TenantID;

                                newDiagnoseConnection.Save(Connection, Transaction);
                            }
                        }
                        #endregion CONNECTED DIAGNOSES
                    }
                }
                #endregion EDIT
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #5
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PR_IPfC_1648 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue      = new FR_Guid();
            var defaultLanguages = ORM_CMN_Language.Query.Search(Connection, Transaction, new ORM_CMN_Language.Query
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            });
            var productFromCatalog = Parameter.Product;
            ORM_CMN_PRO_SubscribedCatalog subscribedCatalog = new ORM_CMN_PRO_SubscribedCatalog();
            var existingCatalog = ORM_CMN_PRO_SubscribedCatalog.Query.Search(Connection, Transaction, new ORM_CMN_PRO_SubscribedCatalog.Query()
            {
                CatalogCodeITL = productFromCatalog.CatalogITL
            });
            if (existingCatalog != null && existingCatalog.Count() > 0)
            {
                subscribedCatalog = existingCatalog.First();
            }
            var supplierID = subscribedCatalog.PublishingSupplier_RefID;

            ORM_CMN_PRO_Product productToCreateUpdate = new ORM_CMN_PRO_Product();
            productToCreateUpdate.CMN_PRO_ProductID = Guid.NewGuid();

            ORM_CMN_PRO_Product.Query productDbQuery = new ORM_CMN_PRO_Product.Query();
            productDbQuery.ProductITL   = productFromCatalog.ProductITL;
            productDbQuery.Tenant_RefID = securityTicket.TenantID;
            productDbQuery.IsDeleted    = false;

            var product = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, productDbQuery);

            if (product != null && product.Count > 0)
            {
                productToCreateUpdate = product.First();

                ORM_CMN_PRO_Dimension.Query dimensionQuery = new ORM_CMN_PRO_Dimension.Query();
                dimensionQuery.Product_RefID = productToCreateUpdate.CMN_PRO_ProductID;
                dimensionQuery.Tenant_RefID  = securityTicket.TenantID;
                dimensionQuery.IsDeleted     = false;

                var dimensions = ORM_CMN_PRO_Dimension.Query.Search(Connection, Transaction, dimensionQuery);
                foreach (var dimension in dimensions)
                {
                    ORM_CMN_PRO_Dimension_Value.Query dimensionValuesQuery = new ORM_CMN_PRO_Dimension_Value.Query();
                    dimensionValuesQuery.Dimensions_RefID = dimension.CMN_PRO_DimensionID;
                    dimensionValuesQuery.Tenant_RefID     = securityTicket.TenantID;
                    var dimensionValues = ORM_CMN_PRO_Dimension_Value.Query.Search(Connection, Transaction, dimensionValuesQuery);
                    foreach (var dimensionValue in dimensionValues)
                    {
                        ORM_CMN_PRO_Variant_DimensionValue.Query dimensionValueVariantQuery = new ORM_CMN_PRO_Variant_DimensionValue.Query();
                        dimensionValueVariantQuery.DimensionValue_RefID = dimensionValue.CMN_PRO_Dimension_ValueID;
                        ORM_CMN_PRO_Variant_DimensionValue.Query.SoftDelete(Connection, Transaction, dimensionValueVariantQuery);
                    }
                    ORM_CMN_PRO_Dimension_Value.Query.SoftDelete(Connection, Transaction, dimensionValuesQuery);
                }

                ORM_CMN_PRO_Dimension.Query.SoftDelete(Connection, Transaction, dimensionQuery);
            }

            productToCreateUpdate.IsImportedFromExternalCatalog = true;
            productToCreateUpdate.Product_Name        = new Dict(ORM_CMN_PRO_Product.TableName);
            productToCreateUpdate.IsDeleted           = false;
            productToCreateUpdate.ProductITL          = productFromCatalog.ProductITL;
            productToCreateUpdate.Product_Description = new Dict(ORM_CMN_PRO_Product.TableName);
            productToCreateUpdate.Tenant_RefID        = securityTicket.TenantID;
            productToCreateUpdate.Product_Number      = productFromCatalog.Code;

            foreach (var lang in defaultLanguages)
            {
                productToCreateUpdate.Product_Name.AddEntry(lang.CMN_LanguageID, productFromCatalog.Name);
                productToCreateUpdate.Product_Description.AddEntry(lang.CMN_LanguageID, productFromCatalog.Description);
            }

            productToCreateUpdate.Save(Connection, Transaction);
            returnValue.Result = productToCreateUpdate.CMN_PRO_ProductID;
            foreach (var customizationToDelete in ORM_CMN_PRO_CUS_Customization.Query.Search(Connection, Transaction, new ORM_CMN_PRO_CUS_Customization.Query()
            {
                Product_RefID = productToCreateUpdate.CMN_PRO_ProductID
            }))
            {
                ORM_CMN_PRO_CUS_Customization.Query.SoftDelete(Connection, Transaction, new ORM_CMN_PRO_CUS_Customization.Query()
                {
                    CMN_PRO_CUS_CustomizationID = customizationToDelete.CMN_PRO_CUS_CustomizationID
                });
                if (ORM_CMN_PRO_CUS_Customization_Variant.Query.Exists(Connection, Transaction, new ORM_CMN_PRO_CUS_Customization_Variant.Query()
                {
                    Customization_RefID = customizationToDelete.CMN_PRO_CUS_CustomizationID
                }))
                {
                    ORM_CMN_PRO_CUS_Customization_Variant.Query.SoftDelete(Connection, Transaction, new ORM_CMN_PRO_CUS_Customization_Variant.Query()
                    {
                        Customization_RefID = customizationToDelete.CMN_PRO_CUS_CustomizationID
                    });
                }
            }
            var customizationOrderSequence = 0;
            if (productFromCatalog.Customizations != null)
            {
                productToCreateUpdate.IsCustomizable = true;
                productToCreateUpdate.Save(Connection, Transaction);
                foreach (var customization in productFromCatalog.Customizations)
                {
                    ORM_CMN_PRO_CUS_Customization customizationToSave = new ORM_CMN_PRO_CUS_Customization();
                    customizationToSave.CMN_PRO_CUS_CustomizationID = Guid.NewGuid();
                    customizationToSave.Customization_Description   = new Dict(ORM_CMN_PRO_CUS_Customization.TableName);
                    customizationToSave.Customization_Name          = new Dict(ORM_CMN_PRO_CUS_Customization.TableName);
                    customizationToSave.IsDeleted     = false;
                    customizationToSave.Product_RefID = productToCreateUpdate.CMN_PRO_ProductID;
                    customizationToSave.Tenant_RefID  = securityTicket.TenantID;
                    customizationToSave.OrderSequence = customizationOrderSequence;
                    customizationOrderSequence++;

                    foreach (var lang in defaultLanguages)
                    {
                        customizationToSave.Customization_Description.UpdateEntry(lang.CMN_LanguageID, customization.Description);
                        customizationToSave.Customization_Name.UpdateEntry(lang.CMN_LanguageID, customization.Name);
                    }
                    customizationToSave.Save(Connection, Transaction);
                    var customizationVariantOrderSequence = 0;
                    foreach (var customizationVariant in customization.CustomizationVariants)
                    {
                        ORM_CMN_PRO_CUS_Customization_Variant customizationVariantsToSave = new ORM_CMN_PRO_CUS_Customization_Variant();
                        customizationVariantsToSave.CMN_PRO_CUS_Customization_VariantID = Guid.NewGuid();
                        customizationVariantsToSave.Customization_RefID       = customizationToSave.CMN_PRO_CUS_CustomizationID;
                        customizationVariantsToSave.CustomizationVariant_Name = new Dict(ORM_CMN_PRO_CUS_Customization_Variant.TableName);
                        customizationVariantsToSave.OrderSequence             = customizationVariantOrderSequence;
                        customizationVariantOrderSequence++;
                        customizationVariantsToSave.IsDeleted    = false;
                        customizationVariantsToSave.Tenant_RefID = securityTicket.TenantID;
                        foreach (var lang in defaultLanguages)
                        {
                            customizationVariantsToSave.CustomizationVariant_Name.UpdateEntry(lang.CMN_LanguageID, customizationVariant.Name);
                        }
                        customizationVariantsToSave.Save(Connection, Transaction);
                    }
                }
            }


            ORM_CMN_PRO_Product_Variant.Query productVariantQuery = new ORM_CMN_PRO_Product_Variant.Query();
            productVariantQuery.CMN_PRO_Product_RefID = productToCreateUpdate.CMN_PRO_ProductID;
            productVariantQuery.Tenant_RefID          = securityTicket.TenantID;
            productVariantQuery.IsDeleted             = false;

            var productVariantsDb = ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction, productVariantQuery);
            List <ORM_CMN_PRO_Dimension>       dimensionsToCreate      = new List <ORM_CMN_PRO_Dimension>();
            List <ORM_CMN_PRO_Dimension_Value> dimensionValuesToCreate = new List <ORM_CMN_PRO_Dimension_Value>();

            foreach (var productVariantFromCatalog in productFromCatalog.Variants)
            {
                ORM_CMN_PRO_Product_Variant.Query variantToCreateQuery = new ORM_CMN_PRO_Product_Variant.Query();
                variantToCreateQuery.ProductVariantITL = productVariantFromCatalog.ITL;
                variantToCreateQuery.Tenant_RefID      = securityTicket.TenantID;
                var isVariantSaved = ORM_CMN_PRO_Product_Variant.Query.Exists(Connection, Transaction, variantToCreateQuery);

                ORM_CMN_PRO_Product_Variant productVariantToCreate = new ORM_CMN_PRO_Product_Variant();
                if (isVariantSaved)
                {
                    productVariantToCreate.Load(Connection, Transaction, ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction, variantToCreateQuery).FirstOrDefault().CMN_PRO_Product_VariantID);
                }
                else
                {
                    productVariantToCreate.CMN_PRO_Product_VariantID = Guid.NewGuid();
                }
                productVariantToCreate.IsStandardProductVariant = productVariantFromCatalog.DefaultVariant;
                productVariantToCreate.CMN_PRO_Product_RefID    = productToCreateUpdate.CMN_PRO_ProductID;
                productVariantToCreate.IsDeleted    = false;
                productVariantToCreate.Tenant_RefID = securityTicket.TenantID;
                productVariantToCreate.IsImportedFromExternalCatalog = true;
                productVariantToCreate.ProductVariantITL             = productVariantFromCatalog.ITL;
                productVariantToCreate.VariantName = new Dict(ORM_CMN_PRO_Product_Variant.TableName);
                foreach (var lang in defaultLanguages)
                {
                    productVariantToCreate.VariantName.UpdateEntry(lang.CMN_LanguageID, productVariantFromCatalog.Name);
                }
                productVariantToCreate.Save(Connection, Transaction);
                ORM_CMN_Price procurementPrice = new ORM_CMN_Price();
                procurementPrice.CMN_PriceID  = Guid.NewGuid();
                procurementPrice.IsDeleted    = false;
                procurementPrice.Tenant_RefID = securityTicket.TenantID;
                procurementPrice.Save(Connection, Transaction);

                foreach (var price in productVariantFromCatalog.PriceGrades)
                {
                    ORM_CMN_Price_Value priceValues = new ORM_CMN_Price_Value();
                    priceValues.Price_RefID = procurementPrice.CMN_PriceID;
                    var procurementPriceAmount = price.SalesPrice ?? 0;
                    priceValues.PriceValue_Amount         = (double)procurementPriceAmount;
                    priceValues.PriceValue_Currency_RefID = subscribedCatalog.SubscribedCatalog_Currency_RefID;
                    priceValues.IsDeleted    = false;
                    priceValues.Tenant_RefID = securityTicket.TenantID;
                    priceValues.Save(Connection, Transaction);
                }

                ORM_CMN_PRO_Product_Supplier productSupplier = new ORM_CMN_PRO_Product_Supplier();
                productSupplier.CMN_BPT_Supplier_RefID        = supplierID;
                productSupplier.CMN_PRO_Product_RefID         = productVariantToCreate.CMN_PRO_Product_RefID;
                productSupplier.CMN_PRO_Product_Variant_RefID = productVariantToCreate.CMN_PRO_Product_VariantID;
                productSupplier.ProcurementPrice_RefID        = procurementPrice.CMN_PriceID;
                productSupplier.Tenant_RefID     = securityTicket.TenantID;
                productSupplier.SupplierPriority = 0;
                productSupplier.IsDeleted        = false;
                productSupplier.Save(Connection, Transaction);


                foreach (var dimension in productVariantFromCatalog.Dimensions)
                {
                    if (dimensionsToCreate.Where(x => x.DimensionName.Contents.First().Content == dimension.Key).Count() == 0)
                    {
                        ORM_CMN_PRO_Dimension dimensionToCreate = new ORM_CMN_PRO_Dimension();
                        dimensionToCreate.DimensionName = new Dict(ORM_CMN_PRO_Dimension.TableName);
                        foreach (var lang in defaultLanguages)
                        {
                            dimensionToCreate.DimensionName.AddEntry(lang.CMN_LanguageID, dimension.Key);
                        }
                        dimensionToCreate.OrderSequence       = dimensionsToCreate.Count() + 1;
                        dimensionToCreate.CMN_PRO_DimensionID = Guid.NewGuid();
                        dimensionToCreate.Product_RefID       = productVariantToCreate.CMN_PRO_Product_RefID;
                        dimensionToCreate.IsDeleted           = false;
                        dimensionToCreate.Tenant_RefID        = securityTicket.TenantID;
                        dimensionsToCreate.Add(dimensionToCreate);
                    }

                    var dimensionValue = dimensionValuesToCreate.Where(x => x.DimensionValue_Text.Contents.First().Content == dimension.Value);
                    ORM_CMN_PRO_Dimension_Value dimensionValueToCreate = new ORM_CMN_PRO_Dimension_Value();
                    if (dimensionValue != null && dimensionValue.Count() > 0)
                    {
                        dimensionValueToCreate = dimensionValue.First();
                    }
                    else
                    {
                        dimensionValueToCreate.DimensionValue_Text = new Dict(ORM_CMN_PRO_Dimension_Value.TableName);
                        foreach (var lang in defaultLanguages)
                        {
                            dimensionValueToCreate.DimensionValue_Text.AddEntry(lang.CMN_LanguageID, dimension.Value);
                        }
                        dimensionValueToCreate.Dimensions_RefID          = dimensionsToCreate.First(x => x.DimensionName.Contents.First().Content == dimension.Key).CMN_PRO_DimensionID;
                        dimensionValueToCreate.CMN_PRO_Dimension_ValueID = Guid.NewGuid();
                        dimensionValueToCreate.OrderSequence             = dimensionValuesToCreate.Count() + 1;
                        dimensionValueToCreate.IsDeleted    = false;
                        dimensionValueToCreate.Tenant_RefID = securityTicket.TenantID;
                        dimensionValuesToCreate.Add(dimensionValueToCreate);
                    }
                    ORM_CMN_PRO_Variant_DimensionValue variantDimensionValueToCreate = new ORM_CMN_PRO_Variant_DimensionValue();
                    variantDimensionValueToCreate.CMN_PRO_Variant_DimensionValueID = Guid.NewGuid();
                    variantDimensionValueToCreate.DimensionValue_RefID             = dimensionValueToCreate.CMN_PRO_Dimension_ValueID;
                    variantDimensionValueToCreate.ProductVariant_RefID             = productVariantToCreate.CMN_PRO_Product_VariantID;
                    variantDimensionValueToCreate.IsDeleted    = false;
                    variantDimensionValueToCreate.Tenant_RefID = securityTicket.TenantID;
                    variantDimensionValueToCreate.Save(Connection, Transaction);
                }
            }
            foreach (var dimensionToCreate in dimensionsToCreate)
            {
                dimensionToCreate.Save(Connection, Transaction);
            }
            foreach (var dimensionValueToCreate in dimensionValuesToCreate)
            {
                dimensionValueToCreate.Save(Connection, Transaction);
            }

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5LI_SLI_1538 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            Guid PurchasingPowerAmount_Current;
            Guid PurchasingPowerAmount_Forecast;
            Guid ResidentialRent_MinPrice;
            Guid ResidentialRent_AveragePrice;
            Guid ResidentialRent_MaxPrice;
            Guid NonResidentialRent_MinPrice;
            Guid NonResidentialRent_AveragePrice;
            Guid NonResidentialRent_MaxPrice;

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Region   = Parameter.City_Region;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.City_AdministrativeDistrict = Parameter.City_AdministrativeDistrict;
            address.City_Name       = Parameter.City_Name;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.Save(Connection, Transaction);

            //for purchasingPowerAmountCurrent
            ORM_CMN_Price price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_PurchasingPowerAmount_Current_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_PurchasingPowerAmount_Current_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            PurchasingPowerAmount_Current = price.CMN_PriceID;

            ORM_CMN_Price_Value.Query priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            List <ORM_CMN_Price_Value> prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            ORM_CMN_Price_Value priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_PurchasingPowerAmount_Current_RefIDValue;
            priceValue.Save(Connection, Transaction);


            //for RegionInformation_PurchasingPowerAmount_Forecast_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            PurchasingPowerAmount_Forecast = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_PurchasingPowerAmount_Forecast_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_MinPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_MinPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_MinPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_MinPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_MinPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_AveragePrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_AveragePrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_AveragePrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_AveragePrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_AveragePrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_ResidentialRent_MaxPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_ResidentialRent_MaxPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_ResidentialRent_MaxPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            ResidentialRent_MaxPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_ResidentialRent_MaxPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_MinPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_MinPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_MinPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_MinPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_MinPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_AveragePrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_AveragePrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_AveragePrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for RegionInformation_NonResidentialRent_MaxPrice_RefID
            price = new ORM_CMN_Price();
            if (Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefID != Guid.Empty)
            {
                var result = price.Load(Connection, Transaction, Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefID);
                if (result.Status != FR_Status.Success || price.CMN_PriceID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            price.Tenant_RefID = securityTicket.TenantID;
            price.Save(Connection, Transaction);

            NonResidentialRent_MaxPrice = price.CMN_PriceID;

            priceValueQuery = new ORM_CMN_Price_Value.Query();
            priceValueQuery.Tenant_RefID = securityTicket.TenantID;
            priceValueQuery.Price_RefID  = price.CMN_PriceID;
            priceValueQuery.IsDeleted    = false;
            prices = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, priceValueQuery);

            priceValue = new ORM_CMN_Price_Value();
            if (prices.Count != 0)
            {
                priceValue.Load(Connection, Transaction, prices[0].CMN_Price_ValueID);
            }
            priceValue.Tenant_RefID      = securityTicket.TenantID;
            priceValue.Price_RefID       = price.CMN_PriceID;
            priceValue.PriceValue_Amount = Parameter.RegionInformation_NonResidentialRent_MaxPrice_RefIDValue;
            priceValue.Save(Connection, Transaction);

            //for regionInfo and region
            ORM_CMN_LOC_Region region = new ORM_CMN_LOC_Region();
            if (Parameter.RegionID != Guid.Empty)
            {
                var result = region.Load(Connection, Transaction, Parameter.RegionID);
                if (result.Status != FR_Status.Success || region.CMN_LOC_RegionID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            ORM_RES_LOC_RegionInformation.Query regionInfo = new ORM_RES_LOC_RegionInformation.Query();
            regionInfo.CMN_LOC_Region_RefID = region.CMN_LOC_RegionID;
            regionInfo.Tenant_RefID         = securityTicket.TenantID;
            regionInfo.IsDeleted            = false;
            List <ORM_RES_LOC_RegionInformation> infos = ORM_RES_LOC_RegionInformation.Query.Search(Connection, Transaction, regionInfo);

            ORM_RES_LOC_RegionInformation info;
            if (infos.Count > 0)
            {
                info = infos[0];
                info.RegionInformation_RegionArea_in_sqkm            = Parameter.RegionInformation_RegionArea_in_sqkm;
                info.RegionInformation_TotalPopulation               = Parameter.RegionInformation_TotalPopulation;
                info.RegionInformation_Population_per_sqkm           = Parameter.RegionInformation_Population_per_sqkm;
                info.RegionInformation_RegionUnemploymentRatePercent = Parameter.RegionInformation_RegionUnemploymentRatePercent;
                info.RegionInformation_NumberOfHouseholds_Current    = Parameter.RegionInformation_NumberOfHouseholds_Current;
                info.RegionInformation_NumberOfHouseholds_Forecast   = Parameter.RegionInformation_NumberOfHouseholds_Forecast;
                info.Tenant_RefID = securityTicket.TenantID;
                info.Save(Connection, Transaction);
            }
            else
            {
                info = new ORM_RES_LOC_RegionInformation();
                info.CMN_LOC_Region_RefID = region.CMN_LOC_RegionID;
                info.RegionInformation_RegionArea_in_sqkm                    = Parameter.RegionInformation_RegionArea_in_sqkm;
                info.RegionInformation_TotalPopulation                       = Parameter.RegionInformation_TotalPopulation;
                info.RegionInformation_Population_per_sqkm                   = Parameter.RegionInformation_Population_per_sqkm;
                info.RegionInformation_RegionUnemploymentRatePercent         = Parameter.RegionInformation_RegionUnemploymentRatePercent;
                info.RegionInformation_NumberOfHouseholds_Current            = Parameter.RegionInformation_NumberOfHouseholds_Current;
                info.RegionInformation_NumberOfHouseholds_Forecast           = Parameter.RegionInformation_NumberOfHouseholds_Forecast;
                info.RegionInformation_PurchasingPowerAmount_Current_RefID   = PurchasingPowerAmount_Current;
                info.RegionInformation_PurchasingPowerAmount_Forecast_RefID  = PurchasingPowerAmount_Forecast;
                info.RegionInformation_ResidentialRent_MinPrice_RefID        = ResidentialRent_MinPrice;
                info.RegionInformation_ResidentialRent_AveragePrice_RefID    = ResidentialRent_AveragePrice;
                info.RegionInformation_ResidentialRent_MaxPrice_RefID        = ResidentialRent_MaxPrice;
                info.RegionInformation_NonResidentialRent_MinPrice_RefID     = NonResidentialRent_MinPrice;
                info.RegionInformation_NonResidentialRent_AveragePrice_RefID = NonResidentialRent_AveragePrice;
                info.RegionInformation_NonResidentialRent_MaxPrice_RefID     = NonResidentialRent_MaxPrice;
                info.Tenant_RefID = securityTicket.TenantID;
                info.Save(Connection, Transaction);
            }

            //save region
            region.Country_RefID = Parameter.Country_RefID;
            region.Tenant_RefID  = securityTicket.TenantID;
            region.Save(Connection, Transaction);

            //for location
            ORM_CMN_LOC_Location location = new ORM_CMN_LOC_Location();
            if (Parameter.CMN_LOC_LocationID != Guid.Empty)
            {
                var result = location.Load(Connection, Transaction, Parameter.CMN_LOC_LocationID);
                if (result.Status != FR_Status.Success || location.CMN_LOC_LocationID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            location.Region_RefID  = region.CMN_LOC_RegionID;
            location.Address_RefID = address.CMN_AddressID;
            location.Tenant_RefID  = securityTicket.TenantID;
            location.Save(Connection, Transaction);

            //add location ref id in realesteProperty
            ORM_RES_RealestateProperty.Query realestatePropertyQuery = new ORM_RES_RealestateProperty.Query();
            realestatePropertyQuery.RES_RealestatePropertyID = Parameter.RealestatePropertyID;
            List <ORM_RES_RealestateProperty> realestates = ORM_RES_RealestateProperty.Query.Search(Connection, Transaction, realestatePropertyQuery);
            ORM_RES_RealestateProperty        realestate  = realestates[0];
            realestate.RealestateProperty_Location_RefID = location.CMN_LOC_LocationID;
            realestate.Save(Connection, Transaction);

            //for locationInformation
            ORM_RES_LOC_LocationInformation locationInformation = new ORM_RES_LOC_LocationInformation();
            if (Parameter.LocationInformationID != Guid.Empty)
            {
                var result = locationInformation.Load(Connection, Transaction, Parameter.LocationInformationID);
                if (result.Status != FR_Status.Success || locationInformation.RES_LOC_LocationInformationID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            locationInformation.CMN_LOC_Location_RefID                   = location.CMN_LOC_LocationID;
            locationInformation.LocationInformation_MapImage_DocID       = Parameter.MapImage;
            locationInformation.LocationInformation_SatelliteImage_DocID = Parameter.SateliteImage;
            locationInformation.LocationInformation_AddressImage_DocID   = Parameter.AddressImage;
            locationInformation.Tenant_RefID = securityTicket.TenantID;
            locationInformation.Save(Connection, Transaction);

            //for meansOfTrasnportation, emmissions, infrastructures...
            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation     transportation;
            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure infrastructure;
            ORM_RES_LOC_LocationInformation_2_Emmission           emmission;
            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality qualitie;
            ORM_RES_LOC_LocationInfo_2_ParkingSituation           parkingSituation;
            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy         residentialVacancy;
            ORM_RES_LOC_LocationInfo_2_CommercialVacancy          commercialVacancy;

            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query transportationQuery = new ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query();
            transportationQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            transportationQuery.Tenant_RefID = securityTicket.TenantID;
            transportationQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_MeansOfTransportation.Query.SoftDelete(Connection, Transaction, transportationQuery);

            if (Parameter.RES_LOC_MeansOfTransportation_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_MeansOfTransportation_RefID)
                {
                    transportation = new ORM_RES_LOC_LocationInformation_2_MeansOfTransportation();
                    transportation.RES_LOC_LocationInformation_RefID   = locationInformation.RES_LOC_LocationInformationID;
                    transportation.RES_LOC_MeansOfTransportation_RefID = guid;
                    transportation.Tenant_RefID = securityTicket.TenantID;
                    transportation.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query infrastructureQuery = new ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query();
            infrastructureQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            infrastructureQuery.Tenant_RefID = securityTicket.TenantID;
            infrastructureQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure.Query.SoftDelete(Connection, Transaction, infrastructureQuery);

            if (Parameter.RES_LOC_SurroundingInfrastructure_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_SurroundingInfrastructure_RefID)
                {
                    infrastructure = new ORM_RES_LOC_LocationInformation_2_SurroundingInfrastructure();
                    infrastructure.RES_LOC_LocationInformation_RefID       = locationInformation.RES_LOC_LocationInformationID;
                    infrastructure.RES_LOC_SurroundingInfrastructure_RefID = guid;
                    infrastructure.Tenant_RefID = securityTicket.TenantID;
                    infrastructure.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_Emmission.Query emmissionQuery = new ORM_RES_LOC_LocationInformation_2_Emmission.Query();
            emmissionQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            emmissionQuery.Tenant_RefID = securityTicket.TenantID;
            emmissionQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_Emmission.Query.SoftDelete(Connection, Transaction, emmissionQuery);

            if (Parameter.RES_LOC_Emmission_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_Emmission_RefID)
                {
                    emmission = new ORM_RES_LOC_LocationInformation_2_Emmission();
                    emmission.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
                    emmission.RES_LOC_Emmission_RefID           = guid;
                    emmission.Tenant_RefID = securityTicket.TenantID;
                    emmission.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query neighborhoodQuery = new ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query();
            neighborhoodQuery.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
            neighborhoodQuery.Tenant_RefID = securityTicket.TenantID;
            neighborhoodQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality.Query.SoftDelete(Connection, Transaction, neighborhoodQuery);

            if (Parameter.RES_LOC_NeighborhoodQuality_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_NeighborhoodQuality_RefID)
                {
                    qualitie = new ORM_RES_LOC_LocationInformation_2_NeighborhoodQuality();
                    qualitie.RES_LOC_LocationInformation_RefID = locationInformation.RES_LOC_LocationInformationID;
                    qualitie.RES_LOC_NeighborhoodQuality_RefID = guid;
                    qualitie.Tenant_RefID = securityTicket.TenantID;
                    qualitie.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query parkingQuery = new ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query();
            parkingQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            parkingQuery.Tenant_RefID = securityTicket.TenantID;
            parkingQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_ParkingSituation.Query.SoftDelete(Connection, Transaction, parkingQuery);

            if (Parameter.RES_LOC_ParkingSituation_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_ParkingSituation_RefID)
                {
                    parkingSituation = new ORM_RES_LOC_LocationInfo_2_ParkingSituation();
                    parkingSituation.RES_LOC_LocationInfo_RefID     = locationInformation.RES_LOC_LocationInformationID;
                    parkingSituation.RES_LOC_ParkingSituation_RefID = guid;
                    parkingSituation.Tenant_RefID = securityTicket.TenantID;
                    parkingSituation.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query residentalQuery = new ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query();
            residentalQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            residentalQuery.Tenant_RefID = securityTicket.TenantID;
            residentalQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_ResidentialVacancy.Query.SoftDelete(Connection, Transaction, residentalQuery);

            if (Parameter.RES_LOC_ResidentialVacancies_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_ResidentialVacancies_RefID)
                {
                    residentialVacancy = new ORM_RES_LOC_LocationInfo_2_ResidentialVacancy();
                    residentialVacancy.RES_LOC_LocationInfo_RefID       = locationInformation.RES_LOC_LocationInformationID;
                    residentialVacancy.RES_LOC_ResidentialVacancy_RefID = guid;
                    residentialVacancy.Tenant_RefID = securityTicket.TenantID;
                    residentialVacancy.Save(Connection, Transaction);
                }
            }

            ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query commercialQuery = new ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query();
            commercialQuery.RES_LOC_LocationInfo_RefID = locationInformation.RES_LOC_LocationInformationID;
            commercialQuery.Tenant_RefID = securityTicket.TenantID;
            commercialQuery.IsDeleted    = false;
            ORM_RES_LOC_LocationInfo_2_CommercialVacancy.Query.SoftDelete(Connection, Transaction, commercialQuery);

            if (Parameter.RES_LOC_CommercialVacancies_RefID != null)
            {
                foreach (Guid guid in Parameter.RES_LOC_CommercialVacancies_RefID)
                {
                    commercialVacancy = new ORM_RES_LOC_LocationInfo_2_CommercialVacancy();
                    commercialVacancy.RES_LOC_LocationInfo_RefID      = locationInformation.RES_LOC_LocationInformationID;
                    commercialVacancy.RES_LOC_CommercialVacancy_RefID = guid;
                    commercialVacancy.Tenant_RefID = securityTicket.TenantID;
                    commercialVacancy.Save(Connection, Transaction);
                }
            }

            returnValue.Result = location.CMN_LOC_LocationID;

            return(returnValue);

            #endregion UserCode
        }
Пример #7
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3AS_SAPDP_1928[] Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Base();
            foreach (var distributionPrice in Parameter)
            {
                foreach (var distributionPriceValue in distributionPrice.DistributionPriceValues.Where(x => x.IsAssigned == false))
                {
                    ORM_CMN_PRO_ASS_DistributionPrice_Value distributionPriceValueToDelete = new ORM_CMN_PRO_ASS_DistributionPrice_Value();
                    FR_Base distributionPriceValueLoad = distributionPriceValueToDelete.Load(Connection, Transaction, distributionPriceValue.CMN_PRO_ASS_DistributionPrice_ValueID);
                    if (distributionPriceValueLoad.Status == FR_Status.Success && distributionPriceValueToDelete.CMN_PRO_ASS_DistributionPrice_ValueID != Guid.Empty)
                    {
                        distributionPriceValueToDelete.IsDeleted = true;
                        distributionPriceValueToDelete.Save(Connection, Transaction);
                    }
                    ORM_CMN_Price priceToCreateToDelete = new ORM_CMN_Price();

                    FR_Base loadPriceToDelete = priceToCreateToDelete.Load(Connection, Transaction, distributionPriceValueToDelete.CMN_Price_RefID);
                    if (loadPriceToDelete.Status == FR_Status.Success && priceToCreateToDelete.CMN_PriceID != Guid.Empty)
                    {
                        priceToCreateToDelete.IsDeleted = true;
                        priceToCreateToDelete.Save(Connection, Transaction);
                    }
                    foreach (var priceValues in distributionPriceValue.Prices)
                    {
                        ORM_CMN_Price_Value priceValueToDelete = new ORM_CMN_Price_Value();
                        FR_Base             loadPriceValue     = priceValueToDelete.Load(Connection, Transaction, priceValues.CMN_Price_ValueID);
                        if (loadPriceValue.Status != FR_Status.Success && priceValueToDelete.CMN_Price_ValueID == Guid.Empty)
                        {
                            priceValueToDelete.IsDeleted = true;
                            priceToCreateToDelete.Save(Connection, Transaction);
                        }
                    }
                }

                foreach (var distributionPriceValue in distributionPrice.DistributionPriceValues.Where(x => x.IsAssigned == true))
                {
                    bool createNewDistributionPriceValue = false;
                    bool pricesExists = true;
                    ORM_CMN_PRO_ASS_DistributionPrice_Value distributionPriceValueToCreateUpdate = new ORM_CMN_PRO_ASS_DistributionPrice_Value();
                    FR_Base distributionPriceLoad = distributionPriceValueToCreateUpdate.Load(Connection, Transaction, distributionPriceValue.CMN_PRO_ASS_DistributionPrice_ValueID);
                    if (distributionPriceLoad.Status != FR_Status.Success || distributionPriceValueToCreateUpdate.CMN_PRO_ASS_DistributionPrice_ValueID == Guid.Empty)
                    {
                        createNewDistributionPriceValue = true;
                    }

                    if (distributionPriceValue.Prices != null)
                    {
                        if (distributionPriceValue.Prices.Where(x => x.PriceValue_Amount > 0).Count() == 0 && !distributionPriceValue.IsDefault)
                        {
                            pricesExists = false;
                            if (!createNewDistributionPriceValue)
                            {
                                distributionPriceValueToCreateUpdate.IsDeleted = true;
                                distributionPriceValueToCreateUpdate.Save(Connection, Transaction);
                            }
                        }
                    }
                    else
                    {
                        pricesExists = false;
                    }

                    // if (pricesExists)
                    //{
                    if (createNewDistributionPriceValue)
                    {
                        distributionPriceValueToCreateUpdate.CMN_PRO_ASS_DistributionPrice_ValueID = distributionPriceValue.CMN_PRO_ASS_DistributionPrice_ValueID;
                    }
                    distributionPriceValueToCreateUpdate.DistributionPrice_RefID = distributionPrice.CMN_PRO_ASS_DistributionPriceID;
                    distributionPriceValueToCreateUpdate.CMN_Price_RefID         = (pricesExists == false) ? Guid.Empty : distributionPriceValue.CMN_Price_RefID;
                    distributionPriceValueToCreateUpdate.Tenant_RefID            = securityTicket.TenantID;
                    distributionPriceValueToCreateUpdate.IsDeleted         = false;
                    distributionPriceValueToCreateUpdate.DefaultPointValue = distributionPriceValue.DefaultPointValue;
                    distributionPriceValueToCreateUpdate.ValidFrom         = distributionPriceValue.ValidFrom;
                    distributionPriceValueToCreateUpdate.ValidThrough      = distributionPriceValue.ValidThrough;


                    //}
                    if (distributionPriceValueToCreateUpdate.DistributionPrice_RefID != Guid.Empty)
                    {
                        distributionPriceValueToCreateUpdate.Save(Connection, Transaction);
                    }

                    ORM_CMN_Price priceToCreateUpdate = new ORM_CMN_Price();
                    bool          createNewPrice      = false;
                    if (distributionPriceValueToCreateUpdate.CMN_Price_RefID != Guid.Empty)
                    {
                        FR_Base loadPrice = priceToCreateUpdate.Load(Connection, Transaction, distributionPriceValueToCreateUpdate.CMN_Price_RefID);
                        if (loadPrice.Status != FR_Status.Success || priceToCreateUpdate.CMN_PriceID == Guid.Empty)
                        {
                            createNewPrice = true;
                        }
                        if (pricesExists)
                        {
                            if (createNewPrice)
                            {
                                priceToCreateUpdate.CMN_PriceID = distributionPriceValue.CMN_Price_RefID;

                                priceToCreateUpdate.IsDeleted = false;
                            }
                            priceToCreateUpdate.IsDeleted    = false;
                            priceToCreateUpdate.Tenant_RefID = securityTicket.TenantID;
                        }
                        else
                        {
                            priceToCreateUpdate.IsDeleted = true;
                        }
                        if (priceToCreateUpdate.CMN_PriceID != Guid.Empty)
                        {
                            priceToCreateUpdate.Save(Connection, Transaction);
                        }

                        foreach (var priceValues in distributionPriceValue.Prices)
                        {
                            bool createNewPriceValue = false;
                            bool hasPrice            = false;
                            ORM_CMN_Price_Value priceValueToCreateUpdate = new ORM_CMN_Price_Value();
                            FR_Base             loadPriceValue           = priceValueToCreateUpdate.Load(Connection, Transaction, priceValues.CMN_Price_ValueID);
                            if (loadPriceValue.Status != FR_Status.Success || priceValueToCreateUpdate.CMN_Price_ValueID == Guid.Empty)
                            {
                                createNewPriceValue = true;
                            }
                            if (priceValues.PriceValue_Amount > 0)
                            {
                                hasPrice = true;
                            }
                            if (distributionPriceValue.IsDefault)
                            {
                                hasPrice = true;
                            }
                            if (!hasPrice && !createNewPriceValue)
                            {
                                priceValueToCreateUpdate.IsDeleted = true;
                            }
                            else if (hasPrice)
                            {
                                if (createNewPriceValue)
                                {
                                    priceValueToCreateUpdate.CMN_Price_ValueID = priceValues.CMN_Price_ValueID;
                                }
                                priceValueToCreateUpdate.Price_RefID = priceToCreateUpdate.CMN_PriceID;
                                priceValueToCreateUpdate.PriceValue_Currency_RefID = priceValues.DefaultCurrency_RefID;
                                priceValueToCreateUpdate.Tenant_RefID      = securityTicket.TenantID;
                                priceValueToCreateUpdate.IsDeleted         = false;
                                priceValueToCreateUpdate.PriceValue_Amount = Double.Parse(priceValues.PriceValue_Amount.ToString());
                            }
                            if (priceValueToCreateUpdate.CMN_Price_ValueID != Guid.Empty)
                            {
                                priceValueToCreateUpdate.Save(Connection, Transaction);
                            }
                        }
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }