protected static FR_L3TX_GTOFTO_1006 Execute(DbConnection Connection, DbTransaction Transaction, P_L3TX_GTOFTO_1006 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3TX_GTOFTO_1006();
            returnValue.Result = new L3TX_GTOFTO_1006();
            var item = new ORM_ACC_TAX_TaxOffice();
            returnValue.Result.TaxOffice = new L3TX_GTOFT_0914();
            var result = item.Load(Connection, Transaction, Parameter.ACC_TAX_TaxOfficeID);

            ORM_CMN_BPT_BusinessParticipant bparticipant = new ORM_CMN_BPT_BusinessParticipant();
            bparticipant.Load(Connection, Transaction, item.CMN_BPT_BusinessParticipant_RefID);
            returnValue.Result.TaxOffice.DisplayName = bparticipant.DisplayName;



            ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
            companyInfo.Load(Connection, Transaction, bparticipant.IfCompany_CMN_COM_CompanyInfo_RefID);

            ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
            ucd.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);

            returnValue.Result.TaxOffice.VATIdentificationNumber = companyInfo.VATIdentificationNumber;
            returnValue.Result.TaxOffice.ACC_TAX_TaxOfficeID     = item.ACC_TAX_TaxOfficeID;
            returnValue.Result.TaxOffice.Country_639_1_ISOCode   = ucd.Country_639_1_ISOCode;

            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Beispiel #2
0
        protected static FR_L5EM_GENFT_1344_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5EM_GENFT_1344_Array();

            List <L5EM_GENFT_1344>         employeeResultList = new List <L5EM_GENFT_1344>();
            ORM_CMN_BPT_EMP_Employee.Query employeeQuery      = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);

            foreach (var employeeItem in employeeList)
            {
                L5EM_GENFT_1344          result   = new L5EM_GENFT_1344();
                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, employeeItem.CMN_BPT_EMP_EmployeeID);
                result.CMN_BPT_EMP_EmployeeID = employeeItem.CMN_BPT_EMP_EmployeeID;

                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);


                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                result.FirstName = personInfo.FirstName;
                result.LastName  = personInfo.LastName;
                employeeResultList.Add(result);

                //Employee workplace history
                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GENFT_1344_EmployeeWorkplaceHistory>     employeeWorkplaceAssignments     = new List <L5EM_GENFT_1344_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GENFT_1344_EmployeeWorkplaceHistory item = new L5EM_GENFT_1344_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();
            }
            returnValue.Result = employeeResultList.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L6MRMS_SEtR_1606 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Base();


            List <ORM_MRS_RUN_MeasurementRun_AccountDownloadCode> downloadCodes = ORM_MRS_RUN_MeasurementRun_AccountDownloadCode.Query.Search(Connection, Transaction, new ORM_MRS_RUN_MeasurementRun_AccountDownloadCode.Query()
            {
                Tenant_RefID         = securityTicket.TenantID,
                IsDeleted            = false,
                MeasurementRun_RefID = Parameter.ReadingSessionId
            });

            foreach (var downloadCode in downloadCodes)
            {
                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                var bpLoad = businessParticipant.Load(Connection, Transaction, downloadCode.Account_RefID);
                if (bpLoad.Status != FR_Status.Success)
                {
                    continue;
                }

                ORM_CMN_BPT_BusinessParticipant_AccessCode bpAccountCode = ORM_CMN_BPT_BusinessParticipant_AccessCode.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_AccessCode.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID
                }).SingleOrDefault();
                if (bpAccountCode == null)
                {
                    continue;
                }

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                var piLoad = personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                if (piLoad.Status != FR_Status.Success)
                {
                    continue;
                }

                //sending email

                string subject = Parameter.EmailSubjectTemplate;
                string body    = String.Format
                                 (
                    Parameter.EmailBodyTemplate,
                    personInfo.FirstName,
                    personInfo.LastName,
                    downloadCode.DownloadCode,
                    bpAccountCode.Code
                                 );
                EmailUtils.SendMail(personInfo.PrimaryEmail, subject, body);
            }

            return(returnValue);

            #endregion UserCode
        }
Beispiel #4
0
        protected static FR_L5PR_CFfC_1332 Execute(DbConnection Connection, DbTransaction Transaction, P_L5PR_CFfC_1332 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5PR_CFfC_1332();
            returnValue.Result = new L5PR_CFfC_1332();

            var tenantQuery = new ORM_CMN_Tenant.Query()
            {
                TenantITL    = Parameter.Pharmacy_TenantITL,
                Tenant_RefID = securityTicket.TenantID
            };

            var pharmacyTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

            //Customer doesn't exist
            if (pharmacyTenant == default(ORM_CMN_Tenant))
            {
                pharmacyTenant = new ORM_CMN_Tenant();
                pharmacyTenant.CMN_TenantID       = Guid.NewGuid();
                pharmacyTenant.TenantITL          = Parameter.Pharmacy_TenantITL;
                pharmacyTenant.Tenant_RefID       = securityTicket.TenantID;
                pharmacyTenant.Creation_Timestamp = DateTime.Now;
                pharmacyTenant.Save(Connection, Transaction);
            }

            var bp = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                IsTenant = true,
                IfTenant_Tenant_RefID = pharmacyTenant.CMN_TenantID,
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false
            }).SingleOrDefault();

            if (bp == default(ORM_CMN_BPT_BusinessParticipant))
            {
                bp = new ORM_CMN_BPT_BusinessParticipant();
                bp.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bp.BusinessParticipantITL        = "";
                bp.DisplayName = Parameter.Pharmacy_CompanyName;
                bp.IsCompany   = true;
                bp.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();
                bp.IsTenant = true;
                bp.IfTenant_Tenant_RefID = pharmacyTenant.CMN_TenantID;
                bp.Tenant_RefID          = securityTicket.TenantID;
                bp.Creation_Timestamp    = DateTime.Now;
                bp.Save(Connection, Transaction);
            }

            returnValue.Result.Pharmacy_TenantID = pharmacyTenant.CMN_TenantID;
            returnValue.Result.Pharmacy_BusinessParticipantID = bp.CMN_BPT_BusinessParticipantID;

            return(returnValue);

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

            //Put your code here
            returnValue.Result = new L5HI_GHIFHIID_1329();

            ORM_HEC_HIS_HealthInsurance_Company.Query healthInsurenceQuery = new ORM_HEC_HIS_HealthInsurance_Company.Query();
            healthInsurenceQuery.HEC_HealthInsurance_CompanyID = Parameter.HEC_HealthInsurance_CompanyID;
            healthInsurenceQuery.Tenant_RefID = securityTicket.TenantID;
            healthInsurenceQuery.IsDeleted    = false;



            List <ORM_HEC_HIS_HealthInsurance_Company> healthInsurances = ORM_HEC_HIS_HealthInsurance_Company.Query.Search(Connection, Transaction, healthInsurenceQuery);
            if (healthInsurances.Count == 0)
            {
                return(null);
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant bpart = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
                {
                    CMN_BPT_BusinessParticipantID = healthInsurances[0].CMN_BPT_BusinessParticipant_RefID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).FirstOrDefault();


                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.Load(Connection, Transaction, bpart.IfCompany_CMN_COM_CompanyInfo_RefID);

                ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
                ucd.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);


                L5HI_GHIFT_1138 healthInsurance = new L5HI_GHIFT_1138();
                healthInsurance.HEC_HealthInsurance_CompanyID = healthInsurances[0].HEC_HealthInsurance_CompanyID;
                healthInsurance.DisplayName = bpart.DisplayName;
                healthInsurance.HealthInsurance_IKNumber = healthInsurances[0].HealthInsurance_IKNumber;
                healthInsurance.Country_ISO = ucd.Country_639_1_ISOCode;
                healthInsurance.Town        = ucd.Town;

                returnValue.Result.HealthInsurance = healthInsurance;
            }

            return(returnValue);

            #endregion UserCode
        }
Beispiel #6
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3L_SLP_1114 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            // CREATE NEW
            if (Parameter.LogisticProviderID == Guid.Empty)
            {
                ORM_CMN_BPT_BusinessParticipant bp = new ORM_CMN_BPT_BusinessParticipant();
                bp.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bp.DisplayName  = Parameter.Name;
                bp.IsCompany    = true;
                bp.Tenant_RefID = securityTicket.TenantID;
                bp.Save(Connection, Transaction);

                ORM_LOG_LogisticsProvider logisticProvider = new ORM_LOG_LogisticsProvider();
                logisticProvider.LOG_LogisticsProviderID = Guid.NewGuid();
                logisticProvider.Ext_CMN_BPT_BusinessParticipant_RefID = bp.CMN_BPT_BusinessParticipantID;
                logisticProvider.IsProviding_TransportServices         = Parameter.IsProvidingTransportServices;
                logisticProvider.IsTrackingAvailable = Parameter.IsTrackingAvailable;
                logisticProvider.Tenant_RefID        = securityTicket.TenantID;
                logisticProvider.Save(Connection, Transaction);

                returnValue.Result = logisticProvider.LOG_LogisticsProviderID;
            }
            // UPDATE EXISTING
            else
            {
                ORM_LOG_LogisticsProvider logisticProvider = new ORM_LOG_LogisticsProvider();
                logisticProvider.Load(Connection, Transaction, Parameter.LogisticProviderID);

                logisticProvider.IsProviding_TransportServices = Parameter.IsProvidingTransportServices;
                logisticProvider.IsTrackingAvailable           = Parameter.IsTrackingAvailable;
                logisticProvider.Save(Connection, Transaction);

                ORM_CMN_BPT_BusinessParticipant bp = new ORM_CMN_BPT_BusinessParticipant();
                bp.Load(Connection, Transaction, logisticProvider.Ext_CMN_BPT_BusinessParticipant_RefID);

                bp.DisplayName = Parameter.Name;
                bp.Save(Connection, Transaction);

                returnValue.Result = Parameter.LogisticProviderID;
            }

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5HI_GHIFT_1138_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5HI_GHIFT_1138_Array();

            List <L5HI_GHIFT_1138> healthInsuranceResult = new List <L5HI_GHIFT_1138>();

            ORM_HEC_HIS_HealthInsurance_Company.Query healthInsurenceQuery = new ORM_HEC_HIS_HealthInsurance_Company.Query();
            healthInsurenceQuery.Tenant_RefID = securityTicket.TenantID;
            healthInsurenceQuery.IsDeleted    = false;
            List <ORM_HEC_HIS_HealthInsurance_Company> healthInsurances = ORM_HEC_HIS_HealthInsurance_Company.Query.Search(Connection, Transaction, healthInsurenceQuery);
            foreach (var healthInsurance in healthInsurances)
            {
                if (healthInsurance.CMN_BPT_BusinessParticipant_RefID == Guid.Empty)
                {
                    continue;
                }

                L5HI_GHIFT_1138 item = new L5HI_GHIFT_1138();
                ORM_CMN_BPT_BusinessParticipant bpart = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
                {
                    CMN_BPT_BusinessParticipantID = healthInsurance.CMN_BPT_BusinessParticipant_RefID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).FirstOrDefault();


                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.Load(Connection, Transaction, bpart.IfCompany_CMN_COM_CompanyInfo_RefID);

                ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
                ucd.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);

                item.HEC_HealthInsurance_CompanyID = healthInsurance.HEC_HealthInsurance_CompanyID;
                item.DisplayName = bpart.DisplayName;
                item.HealthInsurance_IKNumber = healthInsurance.HealthInsurance_IKNumber;
                item.Country_ISO = ucd.Country_639_1_ISOCode;
                item.Town        = ucd.Town;

                healthInsuranceResult.Add(item);
            }

            returnValue.Result = healthInsuranceResult.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3TX_DTO_1148 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Base();

            ORM_ACC_TAX_TaxOffice taxOffice = new ORM_ACC_TAX_TaxOffice();

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

            taxOffice.IsDeleted = true;
            taxOffice.Save(Connection, Transaction);

            ORM_CMN_BPT_BusinessParticipant.Query bptQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            bptQuery.CMN_BPT_BusinessParticipantID = taxOffice.CMN_BPT_BusinessParticipant_RefID;
            bptQuery.IsDeleted    = false;
            bptQuery.Tenant_RefID = securityTicket.TenantID;

            ORM_CMN_BPT_BusinessParticipant bparticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bptQuery).FirstOrDefault();
            bparticipant.IsDeleted = true;
            bparticipant.Save(Connection, Transaction);

            ORM_CMN_COM_CompanyInfo.Query cmpInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
            cmpInfoQuery.CMN_COM_CompanyInfoID = bparticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
            cmpInfoQuery.IsDeleted             = false;
            cmpInfoQuery.Tenant_RefID          = securityTicket.TenantID;

            ORM_CMN_COM_CompanyInfo companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, cmpInfoQuery).FirstOrDefault();
            companyInfo.IsDeleted = true;
            companyInfo.Save(Connection, Transaction);

            return(returnValue);

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

            returnValue.Result = Parameter.Select(hip =>
            {
                var Hip = ORM_HEC_HIS_HealthInsurance_Company.Query.Search(Connection, Transaction, new ORM_HEC_HIS_HealthInsurance_Company.Query()
                {
                    HealthInsurance_IKNumber = hip.IKNumber,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).SingleOrDefault();
                if (Hip != null)
                {
                    return(Hip.CMN_BPT_BusinessParticipant_RefID);
                }
                else
                {
                    var businessParticipantHIP = new ORM_CMN_BPT_BusinessParticipant();
                    businessParticipantHIP.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                    businessParticipantHIP.IsDeleted              = false;
                    businessParticipantHIP.IsCompany              = true;
                    businessParticipantHIP.Tenant_RefID           = securityTicket.TenantID;
                    businessParticipantHIP.Creation_Timestamp     = DateTime.Now;
                    businessParticipantHIP.Modification_Timestamp = DateTime.Now;
                    businessParticipantHIP.DisplayName            = hip.HIPName;
                    businessParticipantHIP.Save(Connection, Transaction);

                    var healthInsuranceCompany                = new ORM_HEC_HIS_HealthInsurance_Company();
                    healthInsuranceCompany.IsDeleted          = false;
                    healthInsuranceCompany.Tenant_RefID       = securityTicket.TenantID;
                    healthInsuranceCompany.Creation_Timestamp = DateTime.Now;
                    healthInsuranceCompany.CMN_BPT_BusinessParticipant_RefID = businessParticipantHIP.CMN_BPT_BusinessParticipantID;
                    healthInsuranceCompany.HealthInsurance_IKNumber          = hip.IKNumber;
                    healthInsuranceCompany.Save(Connection, Transaction);

                    return(businessParticipantHIP.CMN_BPT_BusinessParticipantID);
                }
            }).ToArray();

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3CR_GDLfT_1641 Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L3CR_GDLfT_1641();

            ORM_CMN_BPT_BusinessParticipant businesParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                IsDeleted             = false,
                Tenant_RefID          = securityTicket.TenantID,
                IfTenant_Tenant_RefID = securityTicket.TenantID
            }).FirstOrDefault();

            if (businesParticipant == null)
            {
                returnValue.ErrorMessage = String.Format("BusinessParticipant could not be found for tenant {0}", securityTicket.TenantID.ToString());
                returnValue.Status       = FR_Status.Error_Internal;
                return(returnValue);
            }


            Guid             defaultLanguageId = businesParticipant.DefaultLanguage_RefID;
            ORM_CMN_Language defaultLanguage   = null;

            if (defaultLanguageId != Guid.Empty)
            {
                defaultLanguage = ORM_CMN_Language.Query.Search(Connection, Transaction, new ORM_CMN_Language.Query()
                {
                    IsDeleted      = false,
                    Tenant_RefID   = securityTicket.TenantID,
                    CMN_LanguageID = defaultLanguageId
                }).FirstOrDefault();
            }

            returnValue.Result = new L3CR_GDLfT_1641();
            returnValue.Result.DefaultLanguage = defaultLanguage;


            return(returnValue);

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

            /*
             * @See if Supplier already exists in database
             * */
            ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();

            var supplierQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            supplierQuery.BusinessParticipantITL = Parameter.SupplierITL;
            supplierQuery.Tenant_RefID           = securityTicket.TenantID;
            supplierQuery.IsDeleted = false;

            var supplier_bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, supplierQuery).FirstOrDefault();

            #region if supplier does not exist

            if (supplier_bussinessParticipant == null)
            {
                /*
                 * @Make Supplier Data
                 * */

                var tenantQuery = new ORM_CMN_Tenant.Query()
                {
                    TenantITL    = Parameter.TenantITL,
                    Tenant_RefID = securityTicket.TenantID
                };

                var supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

                if (supplierTenant == default(ORM_CMN_Tenant))
                {
                    supplierTenant = new ORM_CMN_Tenant();
                    supplierTenant.CMN_TenantID       = Guid.NewGuid();
                    supplierTenant.TenantITL          = Parameter.TenantITL;
                    supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                    supplierTenant.Creation_Timestamp = DateTime.Now;
                    supplierTenant.Save(Connection, Transaction);
                }

                supplier.CMN_BPT_SupplierID            = Guid.NewGuid();
                supplier.Ext_BusinessParticipant_RefID = Guid.NewGuid();//supplierBussinessParticipant.CMN_BPT_BusinessParticipantID
                supplier.Creation_Timestamp            = DateTime.Now;
                supplier.IsDeleted    = false;
                supplier.Tenant_RefID = securityTicket.TenantID;
                supplier.Save(Connection, Transaction);

                ORM_CMN_BPT_BusinessParticipant supplierBussinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                supplierBussinessParticipant.CMN_BPT_BusinessParticipantID = supplier.Ext_BusinessParticipant_RefID;
                supplierBussinessParticipant.DisplayName            = Parameter.Supplier_Name;
                supplierBussinessParticipant.BusinessParticipantITL = Parameter.SupplierITL;
                supplierBussinessParticipant.Creation_Timestamp     = DateTime.Now;
                supplierBussinessParticipant.Tenant_RefID           = securityTicket.TenantID;
                supplierBussinessParticipant.IsCompany             = true;
                supplierBussinessParticipant.IsTenant              = true;
                supplierBussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();//companyInfo.CMN_COM_CompanyInfoID
                supplierBussinessParticipant.Save(Connection, Transaction);

                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.CMN_COM_CompanyInfoID = supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfo.Creation_Timestamp    = DateTime.Now;
                companyInfo.Tenant_RefID          = securityTicket.TenantID;
                companyInfo.Contact_UCD_RefID     = Guid.NewGuid();//universalContactDetail.CMN_UniversalContactDetailID
                companyInfo.Save(Connection, Transaction);

                ORM_CMN_UniversalContactDetail universalContactDetail = new ORM_CMN_UniversalContactDetail();
                universalContactDetail.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                universalContactDetail.IsCompany             = true;
                universalContactDetail.Country_639_1_ISOCode = Parameter.CountryISO;
                universalContactDetail.Street_Name           = Parameter.Supplier_Name;
                universalContactDetail.Street_Number         = Parameter.Street_Number;
                universalContactDetail.ZIP                = Parameter.ZIP;
                universalContactDetail.Town               = Parameter.Town;
                universalContactDetail.Region_Code        = Parameter.Region_Code;
                universalContactDetail.Tenant_RefID       = securityTicket.TenantID;
                universalContactDetail.Creation_Timestamp = DateTime.Now;
                universalContactDetail.Save(Connection, Transaction);
            }
            #endregion
            #region if supplier exists , check if its data is changed
            else
            {
                var tenantQuery = new ORM_CMN_Tenant.Query()
                {
                    TenantITL    = Parameter.TenantITL,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                };

                ORM_CMN_Tenant supplierTenant;

                if (ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).Count > 1)
                {
                    supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).First(); //QUICKFIX
                }
                else
                {
                    supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();
                }

                if (supplierTenant == default(ORM_CMN_Tenant))
                {
                    supplierTenant = new ORM_CMN_Tenant();
                    supplierTenant.CMN_TenantID       = Guid.NewGuid();
                    supplierTenant.TenantITL          = Parameter.TenantITL;
                    supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                    supplierTenant.Creation_Timestamp = DateTime.Now;
                    supplierTenant.Save(Connection, Transaction);

                    supplier_bussinessParticipant.IsTenant = true;
                    supplier_bussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                }

                supplier_bussinessParticipant.DisplayName = Parameter.Supplier_Name;
                supplier_bussinessParticipant.Save(Connection, Transaction);

                var query = new ORM_CMN_BPT_Supplier.Query();
                query.Ext_BusinessParticipant_RefID = supplier_bussinessParticipant.CMN_BPT_BusinessParticipantID;
                query.Tenant_RefID = securityTicket.TenantID;
                query.IsDeleted    = false;

                supplier = ORM_CMN_BPT_Supplier.Query.Search(Connection, Transaction, query).First();

                //edit universal contact details

                var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
                companyInfoQuery.CMN_COM_CompanyInfoID = supplier_bussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfoQuery.Tenant_RefID          = securityTicket.TenantID;
                companyInfoQuery.IsDeleted             = false;

                var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First();

                var universalContactDetailQuery = new ORM_CMN_UniversalContactDetail.Query();
                universalContactDetailQuery.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                universalContactDetailQuery.Tenant_RefID = securityTicket.TenantID;
                universalContactDetailQuery.IsDeleted    = false;

                var universalContactDetail = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, universalContactDetailQuery).First();

                universalContactDetail.Country_639_1_ISOCode = Parameter.CountryISO;
                universalContactDetail.Street_Name           = Parameter.Supplier_Name;
                universalContactDetail.Street_Number         = Parameter.Street_Number;
                universalContactDetail.ZIP         = Parameter.ZIP;
                universalContactDetail.Town        = Parameter.Town;
                universalContactDetail.Region_Code = Parameter.Region_Code;
                universalContactDetail.Save(Connection, Transaction);
            }
            #endregion

            returnValue.Result = supplier.CMN_BPT_SupplierID;
            return(returnValue);

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

            L5SO_GSaCOHDfSH_1446 shipmentAndCustomerOrderDetails = null;

            #region Retrieve Shipment and CustomerOrder Details

            P_L5SO_GSaCOHDfSH_1446 shipmentAndCustomerOrderDetailsParameter = new P_L5SO_GSaCOHDfSH_1446();
            shipmentAndCustomerOrderDetailsParameter.ShippingHeaderID = Parameter.ShipmentHeaderID;

            FR_L5SO_GSaCOHDfSH_1446 shipmentAndCustomerOrderDetailsResult = CL5_APOLogistic_ShippingOrder.Atomic.Retrieval.cls_Get_Shipment_and_CustomerOrderHeaderDetails_for_ShipmentHeaderID.Invoke(Connection, Transaction, shipmentAndCustomerOrderDetailsParameter, securityTicket);
            shipmentAndCustomerOrderDetails = shipmentAndCustomerOrderDetailsResult.Result;

            #endregion

            #region Customer name

            var customerName = "";
            if (shipmentAndCustomerOrderDetails != null && shipmentAndCustomerOrderDetails.OrderingCustomer_BusinessParticipant_RefID != Guid.Empty)
            {
                ORM_CMN_BPT_BusinessParticipant bp = new ORM_CMN_BPT_BusinessParticipant();
                var bpResult = bp.Load(Connection, Transaction, shipmentAndCustomerOrderDetails.OrderingCustomer_BusinessParticipant_RefID);
                if (bpResult.Status == FR_Status.Success && bp.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    customerName = bp.DisplayName;
                }
            }

            #endregion

            #region CustomerAddress
            var CustomerAddress = CL5_APOLogistic_ShippingOrder.Atomic.Retrieval.cls_Get_CustomerAddress_from_ShipmentHeaderID.Invoke(Connection, Transaction, new P_L5SO_GCAfSHI_1127 {
                ShipmentHeaderID = Parameter.ShipmentHeaderID
            }, securityTicket);
            #endregion

            #region Organisational unit

            Dict organizationalUnitName = null;
            if (shipmentAndCustomerOrderDetails != null && shipmentAndCustomerOrderDetails.CMN_BPT_CTM_OrganizationalUnit_RefID != Guid.Empty)
            {
                ORM_CMN_BPT_CTM_OrganizationalUnit orgUnit = new ORM_CMN_BPT_CTM_OrganizationalUnit();
                var orgUnitResult = orgUnit.Load(Connection, Transaction, shipmentAndCustomerOrderDetails.CMN_BPT_CTM_OrganizationalUnit_RefID);
                if (orgUnitResult.Status == FR_Status.Success && orgUnit.CMN_BPT_CTM_OrganizationalUnitID != Guid.Empty)
                {
                    organizationalUnitName = orgUnit.OrganizationalUnit_Name;
                }
            }

            #endregion

            L6SO_GASPbtWSvR_1413[] shipmentPositions = new L6SO_GASPbtWSvR_1413[0];

            #region Retrieve Shipment Positions with reservation details (including storage place)

            P_L6SO_GASPbtWSvR_1413 shipmentPositionsParameter = new P_L6SO_GASPbtWSvR_1413();
            shipmentPositionsParameter.ShipmentHeaderID = Parameter.ShipmentHeaderID;
            FR_L6SO_GASPbtWSvR_1413_Array shipmentPositionsForPickingListResult = cls_Get_AllShipmentPositions_bound_to_WarehouseStructure_via_Reservations.Invoke(Connection, Transaction, shipmentPositionsParameter, securityTicket);
            shipmentPositions = shipmentPositionsForPickingListResult.Result;

            #endregion

            #region Retrieve Customer Order Positions for Shipment Positions which are not shipped.

            P_L5CO_GACOPfUSP_1038 customerOrderPositionsForUnshippedShipmentPositionsParameter = new P_L5CO_GACOPfUSP_1038();
            customerOrderPositionsForUnshippedShipmentPositionsParameter.ShipmentHeaderID     = Parameter.ShipmentHeaderID;
            customerOrderPositionsForUnshippedShipmentPositionsParameter.OrganizationalUnitID = Parameter.OrganizationalUnitID;
            FR_L5CO_GACOPfUSP_1038_Array customerOrderPositionsForUnshippedShipmentPositionsResult = cls_Get_AllCustomerOrderPositions_for_Unshipped_ShipmentPositions.Invoke(Connection, Transaction, customerOrderPositionsForUnshippedShipmentPositionsParameter, securityTicket);
            L5CO_GACOPfUSP_1038[]        customerOrderPositions = customerOrderPositionsForUnshippedShipmentPositionsResult.Result;

            #endregion


            //
            // Taking product array from shipment positions previously retrieved.
            // Product array is used for taking product information
            //

            IEnumerable <Guid> productIdList1 = shipmentPositions.Select(x => x.CMN_PRO_Product_RefID).Distinct();
            IEnumerable <Guid> productIdList2 = customerOrderPositions.Select(x => x.CMN_PRO_Product_RefID).Distinct();

            Guid[] productIdArray = productIdList1.Concat(productIdList2).Distinct().ToArray();

            L3AR_GAfAL_0942[] articlesForArticleList = new L3AR_GAfAL_0942[0];

            #region Retrive product details

            if (productIdArray.Length > 0)
            {
                P_L3AR_GAfAL_0942 articlesForArticleListParameter = new P_L3AR_GAfAL_0942();
                articlesForArticleListParameter.ProductID_List = productIdArray;
                FR_L3AR_GAfAL_0942_Array articlesForArticleListResult = cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction, articlesForArticleListParameter, securityTicket);
                articlesForArticleList = articlesForArticleListResult.Result;
            }

            #endregion

            List <ORM_LOG_SHP_Shipment_Note> shipmentNoteList = new List <ORM_LOG_SHP_Shipment_Note>();

            if (shipmentAndCustomerOrderDetails != null)
            {
                shipmentNoteList = ORM_LOG_SHP_Shipment_Note.Query
                                   .Search(Connection, Transaction,
                                           new ORM_LOG_SHP_Shipment_Note.Query {
                    IsDeleted = false, IsNotePrintedOnDeliveryPaper = true, Shipment_Header_RefID = shipmentAndCustomerOrderDetails.LOG_SHP_Shipment_HeaderID
                })
                                   .OrderBy(i => i.Creation_Timestamp).ToList();
            }

            List <L6LG_GDfDLR_1522c> commentList = new List <L6LG_GDfDLR_1522c>();
            foreach (ORM_LOG_SHP_Shipment_Note shipmentNote in shipmentNoteList)
            {
                L6LG_GDfDLR_1522c comment = new L6LG_GDfDLR_1522c();

                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                FR_Base bpLoad = businessParticipant.Load(Connection, Transaction, shipmentNote.CreatedBy_BusinessParticipant_RefID);
                if (bpLoad.Status == FR_Status.Success)
                {
                    comment.Name = businessParticipant.DisplayName;
                }
                comment.Comment = shipmentNote.Comment;
                commentList.Add(comment);
            }

            #region Building return object

            List <L6LG_GDfDLR_1522a> tempShipmentPositions = new List <L6LG_GDfDLR_1522a>();

            foreach (L6SO_GASPbtWSvR_1413 shipmentPosition in shipmentPositions)
            {
                L6LG_GDfDLR_1522a tempShipmentPosition = new L6LG_GDfDLR_1522a();
                tempShipmentPosition.ShipmentPositionDetails = shipmentPosition;
                tempShipmentPosition.ProductDetails          = articlesForArticleList.FirstOrDefault(a => a.CMN_PRO_ProductID == shipmentPosition.CMN_PRO_Product_RefID);
                tempShipmentPositions.Add(tempShipmentPosition);
            }

            List <L6LG_GDfDLR_1522b> tempCustomerOrderPositions = new List <L6LG_GDfDLR_1522b>();

            foreach (L5CO_GACOPfUSP_1038 customerOrderPosition in customerOrderPositions)
            {
                L6LG_GDfDLR_1522b tempCustomerOrderPosition = new L6LG_GDfDLR_1522b();
                tempCustomerOrderPosition.CustomerOrderPositionDetails = customerOrderPosition;
                tempCustomerOrderPosition.ProductDetails = articlesForArticleList.FirstOrDefault(a => a.CMN_PRO_ProductID == customerOrderPosition.CMN_PRO_Product_RefID);
                tempCustomerOrderPositions.Add(tempCustomerOrderPosition);
            }

            returnValue.Result = new L6LG_GDfDLR_1522();
            returnValue.Result.CustomerName                    = customerName;
            returnValue.Result.StreetAndNumber                 = CustomerAddress != null && CustomerAddress.Result != null  ? CustomerAddress.Result.Street_Name + " " + CustomerAddress.Result.Street_Number : "keine Kundenadresse";
            returnValue.Result.ZipAndCity                      = CustomerAddress != null && CustomerAddress.Result != null ? CustomerAddress.Result.ZIP + " " + CustomerAddress.Result.Town : "keine Kundenadresse";
            returnValue.Result.OrganizationalUnitName          = organizationalUnitName;
            returnValue.Result.ShipmentPositionList            = tempShipmentPositions.ToArray();
            returnValue.Result.CustomerOrderPositionList       = tempCustomerOrderPositions.ToArray();
            returnValue.Result.ShipmentAndCustomerOrderDetails = shipmentAndCustomerOrderDetails;
            returnValue.Result.CommentList                     = commentList.ToArray();

            #endregion

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5EM_GEFT_0959_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5EM_GEFT_0959_Array();
            List <L5EM_GEFT_0959>          employeeResultList = new List <L5EM_GEFT_0959>();
            ORM_CMN_BPT_EMP_Employee.Query employeeQuery      = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);

            foreach (var employeeItem in employeeList)
            {
                L5EM_GEFT_0959           result   = new L5EM_GEFT_0959();
                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, employeeItem.CMN_BPT_EMP_EmployeeID);
                result.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
                result.Staff_Number           = employee.Staff_Number;
                result.StandardFunction       = employee.StandardFunction;

                ORM_USR_Account.Query accountQuery = new ORM_USR_Account.Query();
                accountQuery.BusinessParticipant_RefID = employee.BusinessParticipant_RefID;
                accountQuery.Tenant_RefID = securityTicket.TenantID;
                accountQuery.IsDeleted    = false;
                ORM_USR_Account account = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery).FirstOrDefault();
                if (account != null)
                {
                    result.USR_AccountID = account.USR_AccountID;
                }

                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                result.CMN_BPT_BusinessParticipantID = businessParticipant.CMN_BPT_BusinessParticipantID;
                result.DisplayName = businessParticipant.DisplayName;

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                result.CMN_PER_PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                result.FirstName            = personInfo.FirstName;
                result.LastName             = personInfo.LastName;
                result.PrimaryEmail         = personInfo.PrimaryEmail;
                result.Title = personInfo.Title;
                result.ProfileImage_Document_RefID = personInfo.ProfileImage_Document_RefID;
                result.BirthDate = personInfo.BirthDate;

                ORM_CMN_BPT_EMP_EmploymentRelationship.Query workingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship.Query();
                workingContractQuery.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                workingContractQuery.IsDeleted      = false;
                workingContractQuery.Tenant_RefID   = securityTicket.TenantID;
                ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = ORM_CMN_BPT_EMP_EmploymentRelationship.Query.Search(Connection, Transaction, workingContractQuery).FirstOrDefault();

                result.CMN_BPT_EMP_EmploymentRelationshipID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                result.Work_StartDate = employmentRelationship.Work_StartDate;
                result.Work_EndDate   = employmentRelationship.Work_EndDate;

                //Address
                if (personInfo.Address_RefID != Guid.Empty)
                {
                    ORM_CMN_Address address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    result.CMN_AddressID = address.CMN_AddressID;
                    result.Street_Name   = address.Street_Name;
                    result.Street_Number = address.Street_Number;
                    result.City_AdministrativeDistrict = address.City_AdministrativeDistrict;
                    result.City_Region     = address.City_Region;
                    result.City_Name       = address.City_Name;
                    result.City_PostalCode = address.City_PostalCode;
                    result.Province_Name   = address.Province_Name;
                    result.Country_Name    = address.Country_Name;
                    result.Country_ISOCode = address.Country_ISOCode;
                }

                //Contacts
                ORM_CMN_PER_CommunicationContact.Query comunicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query();
                comunicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                comunicationContactQuery.Tenant_RefID     = securityTicket.TenantID;
                comunicationContactQuery.IsDeleted        = false;
                List <ORM_CMN_PER_CommunicationContact> comunicationContacts       = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, comunicationContactQuery);
                List <L5EM_GEFT_0959_Contacts>          resultComunicationContacts = new List <L5EM_GEFT_0959_Contacts>();
                foreach (var comunicationContact in comunicationContacts)
                {
                    ORM_CMN_PER_CommunicationContact_Type contactType = new ORM_CMN_PER_CommunicationContact_Type();
                    contactType.Load(Connection, Transaction, comunicationContact.CMN_PER_CommunicationContactID);
                    L5EM_GEFT_0959_Contacts resultComunicationContact = new L5EM_GEFT_0959_Contacts();
                    resultComunicationContact.CMN_PER_CommunicationContact_TypeID = contactType.CMN_PER_CommunicationContact_TypeID;
                    resultComunicationContact.CMN_PER_CommunicationContactID      = comunicationContact.CMN_PER_CommunicationContactID;
                    resultComunicationContact.Content = comunicationContact.Content;
                    resultComunicationContact.Type    = contactType.Type;
                    resultComunicationContacts.Add(resultComunicationContact);
                }
                result.Contacts = resultComunicationContacts.ToArray();


                //Employee workplace history
                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GEFT_0959_EmployeeWorkplaceHistory>      employeeWorkplaceAssignments     = new List <L5EM_GEFT_0959_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GEFT_0959_EmployeeWorkplaceHistory item = new L5EM_GEFT_0959_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();


                //Contracts

                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query contractTermQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                contractTermQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                contractTermQuery.IsDeleted    = false;
                contractTermQuery.Tenant_RefID = securityTicket.TenantID;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> contracts = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, contractTermQuery);
                List <L5EM_GEFT_0959_WorkingContracts> resultContracts = new List <L5EM_GEFT_0959_WorkingContracts>();
                foreach (var contractToRelationship in contracts)
                {
                    L5EM_GEFT_0959_WorkingContracts resultContract = new L5EM_GEFT_0959_WorkingContracts();

                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    workingContract.Load(Connection, Transaction, contractToRelationship.WorkingContract_RefID);
                    if (!workingContract.IsDeleted)
                    {
                        resultContract.CMN_BPT_EMP_WorkingContractID = workingContract.CMN_BPT_EMP_WorkingContractID;
                        resultContract.EmploymentRelationshipToWorkingContractAssignmentID = contractToRelationship.AssignmentID;
                        resultContract.IsWorkingContract_Active     = contractToRelationship.IsContract_Active;
                        resultContract.Contract_StartDate           = workingContract.Contract_StartDate;
                        resultContract.Contract_EndDate             = workingContract.Contract_EndDate;
                        resultContract.IsContractEndDateDefined     = workingContract.IsContractEndDateDefined;
                        resultContract.IsWorkTimeCalculated_InDays  = workingContract.IsWorkTimeCalculated_InDays;
                        resultContract.IsWorkTimeCalculated_InHours = workingContract.IsWorkTimeCalculated_InHours;
                        resultContract.R_WorkTime_DaysPerWeek       = workingContract.R_WorkTime_DaysPerWeek;
                        resultContract.R_WorkTime_HoursPerWeek      = workingContract.R_WorkTime_HoursPerWeek;

                        //Office hours
                        ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query workingContractTermToWorkingDayQuery = new ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query();
                        workingContractTermToWorkingDayQuery.CMN_BPT_EMP_WorkingContract_RefID = workingContract.CMN_BPT_EMP_WorkingContractID;
                        workingContractTermToWorkingDayQuery.Tenant_RefID = securityTicket.TenantID;
                        workingContractTermToWorkingDayQuery.IsDeleted    = false;
                        List <ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay> workingDayAssigments    = ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query.Search(Connection, Transaction, workingContractTermToWorkingDayQuery);
                        List <L5EM_GEFT_0959_WeeklyOfficeHours>             resultWeeklyOfficeHours = new List <L5EM_GEFT_0959_WeeklyOfficeHours>();
                        foreach (var workingDayAssigment in workingDayAssigments)
                        {
                            ORM_CMN_CAL_WeeklyOfficeHours_Interval interval = new ORM_CMN_CAL_WeeklyOfficeHours_Interval();
                            interval.Load(Connection, Transaction, workingDayAssigment.CMN_CAL_WeeklyOfficeHours_Interval_RefID);

                            L5EM_GEFT_0959_WeeklyOfficeHours resultOfficeHour = new L5EM_GEFT_0959_WeeklyOfficeHours();
                            resultOfficeHour.CMN_CAL_WeeklyOfficeHours_IntervalID = interval.CMN_CAL_WeeklyOfficeHours_IntervalID;
                            resultOfficeHour.IsFriday           = interval.IsFriday;
                            resultOfficeHour.IsMonday           = interval.IsMonday;
                            resultOfficeHour.IsSaturday         = interval.IsSaturday;
                            resultOfficeHour.IsSunday           = interval.IsSunday;
                            resultOfficeHour.IsThursday         = interval.IsThursday;
                            resultOfficeHour.IsTuesday          = interval.IsTuesday;
                            resultOfficeHour.IsWednesday        = interval.IsWednesday;
                            resultOfficeHour.IsWholeDay         = interval.IsWholeDay;
                            resultOfficeHour.TimeFrom_InMinutes = interval.TimeFrom_InMinutes;
                            resultOfficeHour.TimeTo_InMinutes   = interval.TimeTo_InMinutes;
                            resultWeeklyOfficeHours.Add(resultOfficeHour);
                        }
                        resultContract.WeeklyOfficeHours = resultWeeklyOfficeHours.ToArray();


                        //Allowed absence reasons
                        ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query AllowedAbsenceReasonQuery = new ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query();
                        AllowedAbsenceReasonQuery.WorkingContract_RefID = resultContract.CMN_BPT_EMP_WorkingContractID;
                        AllowedAbsenceReasonQuery.Tenant_RefID          = securityTicket.TenantID;
                        AllowedAbsenceReasonQuery.IsDeleted             = false;
                        List <ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason> allowedAbsenceReasons       = ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query.Search(Connection, Transaction, AllowedAbsenceReasonQuery);
                        List <L5EM_GEFT_0959_WorkingContractToLeaveRequest>         resultAllowedAbsenceReasons = new List <L5EM_GEFT_0959_WorkingContractToLeaveRequest>();
                        foreach (var allowedAbsenceReason in allowedAbsenceReasons)
                        {
                            ORM_CMN_BPT_STA_AbsenceReason absenceReason = new ORM_CMN_BPT_STA_AbsenceReason();
                            absenceReason.Load(Connection, Transaction, allowedAbsenceReason.STA_AbsenceReason_RefID);

                            L5EM_GEFT_0959_WorkingContractToLeaveRequest resultReasonresultReason = new L5EM_GEFT_0959_WorkingContractToLeaveRequest();
                            resultReasonresultReason.CMN_BPT_EMP_Employee_WorkingContract_AllowedAbsenceReasonID = allowedAbsenceReason.CMN_BPT_EMP_WorkingContract_AllowedAbsenceReasonID;
                            resultReasonresultReason.STA_AbsenceReason_RefID          = absenceReason.CMN_BPT_STA_AbsenceReasonID;
                            resultReasonresultReason.IsAbsenceCalculated_InDays       = allowedAbsenceReason.IsAbsenceCalculated_InDays;
                            resultReasonresultReason.IsAbsenceCalculated_InHours      = allowedAbsenceReason.IsAbsenceCalculated_InHours;
                            resultReasonresultReason.ContractAllowedAbsence_per_Month = allowedAbsenceReason.ContractAllowedAbsence_per_Month;
                            resultAllowedAbsenceReasons.Add(resultReasonresultReason);
                        }
                        resultContract.WorkingContractToLeaveRequest = resultAllowedAbsenceReasons.ToArray();

                        resultContracts.Add(resultContract);
                    }
                }
                result.WorkingContracts = resultContracts.ToArray();
                employeeResultList.Add(result);
            }
            returnValue.Result = employeeResultList.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Beispiel #14
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_SSU_1847 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var userAccount = new ORM_USR_Account();
            var result      = userAccount.Load(Connection, Transaction, Parameter.USR_AccountID);

            if (result.Status == FR_Status.Success)
            {
                //Get business participant via userAccount
                var businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, userAccount.BusinessParticipant_RefID);

                //Load person
                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                //Load communication contacts for person
                P_L2CN_GCCfPI_1222 contactsParam = new P_L2CN_GCCfPI_1222();
                contactsParam.PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                var contactsForPersonInfo = cls_Get_ComunicationContacts_for_PersonInfoID.Invoke(Connection, Transaction, contactsParam, securityTicket).Result.ToList();

                if (!Parameter.IsInitialSave)
                {
                    if (Parameter.IsDeleted)
                    {
                        #region Delete

                        var queryApplicationSubscription = new ORM_CMN_Account_ApplicationSubscription.Query();
                        queryApplicationSubscription.Application_RefID = Parameter.ApplicationID;
                        queryApplicationSubscription.Account_RefID     = userAccount.USR_AccountID;
                        queryApplicationSubscription.Tenant_RefID      = securityTicket.TenantID;

                        var foundApplicationSubscription = ORM_CMN_Account_ApplicationSubscription.Query.SoftDelete(Connection, Transaction, queryApplicationSubscription);

                        return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

                        #endregion
                    }

                    #region Edit


                    personInfo.FirstName = Parameter.FirstName_ContactPerson;
                    personInfo.LastName  = Parameter.LastName_ContactPerson;
                    personInfo.Save(Connection, Transaction);

                    var employeeTemp = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                    {
                        BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();

                    if (employeeTemp == null)
                    {
                        var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                        newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                        newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                        newEmployee.StandardFunction          = "APOAdminEmployee";
                        newEmployee.Tenant_RefID = securityTicket.TenantID;
                        newEmployee.Save(Connection, Transaction);
                    }


                    var address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    address.Street_Name     = Parameter.Street_Name;
                    address.Street_Number   = Parameter.Street_Number;
                    address.City_Name       = Parameter.Town;
                    address.City_PostalCode = Parameter.ZIP;
                    address.Save(Connection, Transaction);


                    try
                    {
                        //telephone
                        var telephone = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Phone))
                                        .First().Contacts;

                        if (telephone.Count() == 1)
                        {
                            var contactID = telephone[0].CMN_PER_CommunicationContactID;

                            var contactTelephone = new ORM_CMN_PER_CommunicationContact();
                            contactTelephone.Load(Connection, Transaction, contactID);
                            contactTelephone.Content = Parameter.Contact_Telephone;
                            contactTelephone.Save(Connection, Transaction);
                        }
                    }
                    catch
                    {
                        //Log this
                    }

                    #region CommentedUsefull-PreviousWayOfContactEmailHandling

                    //try
                    //{
                    //    //email
                    //    var email = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Email))
                    //        .First().Contacts;

                    //    if (email.Count() == 1)
                    //    {
                    //        var contactID = email[0].CMN_PER_CommunicationContactID;

                    //        var contactEmail = new ORM_CMN_PER_CommunicationContact();
                    //        contactEmail.Load(Connection, Transaction, contactID);
                    //        contactEmail.Content = Parameter.Contact_Email;
                    //        contactEmail.Save(Connection, Transaction);
                    //    }

                    //}
                    //catch
                    //{

                    //    //Log this
                    //}

                    #endregion

                    #endregion
                }

                #region SaveGroup

                var userAccountToGroup = ORM_USR_Account_2_Group.Query.Search(Connection, Transaction, new ORM_USR_Account_2_Group.Query()
                {
                    USR_Account_RefID = userAccount.USR_AccountID,
                    Tenant_RefID      = securityTicket.TenantID,
                    IsDeleted         = false
                }).SingleOrDefault();


                if (userAccountToGroup == null)
                {
                    var newGroup = new ORM_USR_Account_2_Group();
                    newGroup.AssignmentID       = Guid.NewGuid();
                    newGroup.USR_Account_RefID  = userAccount.USR_AccountID;
                    newGroup.USR_Group_RefID    = Parameter.USR_GroupID;
                    newGroup.Creation_Timestamp = DateTime.Now;
                    newGroup.Tenant_RefID       = securityTicket.TenantID;
                    newGroup.Save(Connection, Transaction);
                }
                else
                {
                    userAccountToGroup.USR_Group_RefID = Parameter.USR_GroupID;
                    userAccountToGroup.Save(Connection, Transaction);
                }

                #endregion

                #region SaveEmployee

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                {
                    BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (employee == null)
                {
                    var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                    newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                    newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                    newEmployee.StandardFunction          = "APOAdminEmployee";
                    newEmployee.Tenant_RefID = securityTicket.TenantID;
                    newEmployee.Save(Connection, Transaction);
                }

                #endregion

                #region CreateOrUpdateContactEmail

                var emailTypeProperty     = EnumUtils.GetEnumDescription(EComunactionContactType.Email);
                var contactEmailTypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query();
                contactEmailTypeQuery.Type         = emailTypeProperty;
                contactEmailTypeQuery.Tenant_RefID = securityTicket.TenantID;
                var contactEmailType = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, contactEmailTypeQuery).FirstOrDefault();

                //Search for default contact email and create it if don't exist

                var defaultContactEmailQuery = new ORM_CMN_PER_CommunicationContact.Query();
                defaultContactEmailQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                defaultContactEmailQuery.Contact_Type     = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                defaultContactEmailQuery.Tenant_RefID     = securityTicket.TenantID;
                var defaultContactEmail = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, defaultContactEmailQuery).FirstOrDefault();

                if (defaultContactEmail == null)
                {
                    defaultContactEmail = new ORM_CMN_PER_CommunicationContact();
                    defaultContactEmail.PersonInfo_RefID        = personInfo.CMN_PER_PersonInfoID;
                    defaultContactEmail.Contact_Type            = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                    defaultContactEmail.IsDefaultForContactType = true;
                    defaultContactEmail.Tenant_RefID            = securityTicket.TenantID;
                }

                defaultContactEmail.Content = Parameter.Contact_Email;
                defaultContactEmail.IsDefaultForContactType = true;
                defaultContactEmail.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                FR_Guid error = new FR_Guid();
                error.ErrorMessage = "No Such ID.";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

            #endregion UserCode
        }
Beispiel #15
0
        protected static FR_L5WA_GWAFWA_0907 Execute(DbConnection Connection, DbTransaction Transaction, P_L5WA_GWAFWA_0907 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5WA_GWAFWA_0907();
            returnValue.Result = new L5WA_GWAFWA_0907();

            L5WA_GWAFT_1201 result = new L5WA_GWAFT_1201();

            ORM_CMN_STR_PPS_WorkArea item = new ORM_CMN_STR_PPS_WorkArea();
            if (Parameter.WorkAreaID != Guid.Empty)
            {
                var resultWorkplace = item.Load(Connection, Transaction, Parameter.WorkAreaID);
                if (resultWorkplace.Status != FR_Status.Success || item.CMN_STR_PPS_WorkAreaID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(null);
                }
            }
            result.CMN_CAL_CalendarInstance_RefID   = item.CMN_CAL_CalendarInstance_RefID;
            result.CMN_BPT_STA_SettingProfile_RefID = item.CMN_BPT_STA_SettingProfile_RefID;
            result.Office_RefID             = item.Office_RefID;
            result.Parent_RefID             = item.Parent_RefID;
            result.WorkAreaName             = item.Name;
            result.WorkAreaDescription      = item.Description;
            result.ShortName                = item.ShortName;
            result.CMN_STR_PPS_WorkAreaID   = item.CMN_STR_PPS_WorkAreaID;
            result.Default_StartWorkingHour = item.Default_StartWorkingHour;



            ORM_CMN_STR_PPS_WorkArea_2_CostCenter.Query workareaToCostcenterQuery = new ORM_CMN_STR_PPS_WorkArea_2_CostCenter.Query();
            workareaToCostcenterQuery.WorkArea_RefID = Parameter.WorkAreaID;
            workareaToCostcenterQuery.Tenant_RefID   = securityTicket.TenantID;
            workareaToCostcenterQuery.IsDeleted      = false;
            List <ORM_CMN_STR_PPS_WorkArea_2_CostCenter> workareaToCostcenterList = ORM_CMN_STR_PPS_WorkArea_2_CostCenter.Query.Search(Connection, Transaction, workareaToCostcenterQuery);
            if (workareaToCostcenterList.Count != 0)
            {
                L5WA_GWAFT_1201_Costcenter costCenter     = new L5WA_GWAFT_1201_Costcenter();
                ORM_CMN_STR_CostCenter     costCenterItem = new ORM_CMN_STR_CostCenter();
                costCenterItem.Load(Connection, Transaction, workareaToCostcenterList[0].CostCenter_RefID);
                if (!costCenterItem.IsDeleted)
                {
                    costCenter.AssignmentID         = workareaToCostcenterList[0].AssignmentID;
                    costCenter.CMN_STR_CostCenterID = workareaToCostcenterList[0].CostCenter_RefID;
                    costCenter.CostcenterName       = costCenterItem.Name;
                    costCenter.InternalID           = costCenterItem.InternalID;
                    result.Costcenter = costCenter;
                }
            }


            var responsiblePersonsQuery = new ORM_CMN_STR_PPS_WorkArea_ResponsiblePerson.Query();
            responsiblePersonsQuery.Tenant_RefID   = securityTicket.TenantID;
            responsiblePersonsQuery.WorkArea_RefID = item.CMN_STR_PPS_WorkAreaID;
            responsiblePersonsQuery.IsDeleted      = false;
            var responsiblePersonsList = ORM_CMN_STR_PPS_WorkArea_ResponsiblePerson.Query.Search(Connection, Transaction, responsiblePersonsQuery);
            List <L5WA_GWAFT_1201_ResponsiblePersons> responsiblePresonsResultList = new List <L5WA_GWAFT_1201_ResponsiblePersons>();
            foreach (var responsiblePerson in responsiblePersonsList)
            {
                L5WA_GWAFT_1201_ResponsiblePersons responsiblePersonResult = new L5WA_GWAFT_1201_ResponsiblePersons();
                responsiblePersonResult.CMN_BPT_EMP_EmployeeID = responsiblePerson.CMN_BPT_EMP_Employee_RefID;
                responsiblePersonResult.CMN_STR_PPS_WorkArea_ResponsiblePersonID = responsiblePerson.CMN_STR_PPS_WorkArea_ResponsiblePersonID;

                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, responsiblePerson.CMN_BPT_EMP_Employee_RefID);

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                responsiblePersonResult.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
                responsiblePersonResult.FirstName            = person.FirstName;
                responsiblePersonResult.LastName             = person.LastName;
                responsiblePersonResult.CMN_PER_PersonInfoID = person.CMN_PER_PersonInfoID;
                responsiblePersonResult.WorkArea_RefID       = item.CMN_STR_PPS_WorkAreaID;

                responsiblePresonsResultList.Add(responsiblePersonResult);
            }

            result.ResponsiblePersons = responsiblePresonsResultList.ToArray();

            returnValue.Result.workarea = result;
            //Put your code here
            return(returnValue);

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



            FR_Base result = new FR_Base();
            //Put your code here
            var item = new ORM_HEC_HIS_HealthInsurance_Company();
            if (Parameter.HEC_HealthInsurance_CompanyID != Guid.Empty)
            {
                result = item.Load(Connection, Transaction, Parameter.HEC_HealthInsurance_CompanyID);
                if (result.Status != FR_Status.Success || item.HEC_HealthInsurance_CompanyID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            item.HealthInsurance_IKNumber = Parameter.HealthInsurance_IKNumber;
            item.Tenant_RefID             = securityTicket.TenantID;

            ORM_CMN_BPT_BusinessParticipant bpart = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
            {
                CMN_BPT_BusinessParticipantID = item.CMN_BPT_BusinessParticipant_RefID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).FirstOrDefault();
            if (bpart == null || bpart.CMN_BPT_BusinessParticipantID == Guid.Empty)
            {
                bpart = new ORM_CMN_BPT_BusinessParticipant();
            }
            bpart.DisplayName  = Parameter.CompanyName;
            bpart.Tenant_RefID = securityTicket.TenantID;


            item.CMN_BPT_BusinessParticipant_RefID = bpart.CMN_BPT_BusinessParticipantID;

            ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
            result = companyInfo.Load(Connection, Transaction, bpart.IfCompany_CMN_COM_CompanyInfo_RefID);
            if (result.Status != FR_Status.Success || companyInfo.CMN_COM_CompanyInfoID == Guid.Empty)
            {
                companyInfo = new ORM_CMN_COM_CompanyInfo();
            }
            bpart.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            bpart.Save(Connection, Transaction);

            ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
            result = ucd.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);
            if (result.Status != FR_Status.Success || ucd.CMN_UniversalContactDetailID == Guid.Empty)
            {
                ucd = new ORM_CMN_UniversalContactDetail();
            }
            companyInfo.Tenant_RefID      = securityTicket.TenantID;
            companyInfo.Contact_UCD_RefID = ucd.CMN_UniversalContactDetailID;
            companyInfo.Save(Connection, Transaction);


            returnValue.Result = item.HEC_HealthInsurance_CompanyID;

            if (Parameter.Country_ISO != "")
            {
                ucd.Country_639_1_ISOCode = Parameter.Country_ISO;
                ucd.Town         = Parameter.Town;
                ucd.Tenant_RefID = securityTicket.TenantID;
            }
            ucd.Save(Connection, Transaction);

            item.Save(Connection, Transaction);


            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3TE_CTITS_1108 Execute(DbConnection Connection, DbTransaction Transaction, P_L3TE_CTITS_1108 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3TE_CTITS_1108();
            returnValue.Result = new L3TE_CTITS_1108();
            returnValue.Status = FR_Status.Error_Internal;

            #region Load or Create Tenant
            var tenantQuery = new ORM_CMN_Tenant.Query()
            {
                TenantITL    = Parameter.TenantITL,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            };

            var customerTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

            if (customerTenant == default(ORM_CMN_Tenant))
            {
                customerTenant = new ORM_CMN_Tenant();
                customerTenant.CMN_TenantID                 = Guid.NewGuid();
                customerTenant.TenantITL                    = Parameter.TenantITL;
                customerTenant.Tenant_RefID                 = securityTicket.TenantID;
                customerTenant.Creation_Timestamp           = DateTime.Now;
                customerTenant.UniversalContactDetail_RefID = Guid.NewGuid();
                if (customerTenant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create BusinessParticipant
            var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                IsTenant = true,
                IfTenant_Tenant_RefID = customerTenant.CMN_TenantID,
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false
            }).SingleOrDefault();

            if (businessParticipant == default(ORM_CMN_BPT_BusinessParticipant))
            {
                businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                businessParticipant.BusinessParticipantITL        = Parameter.BusinessParticipantITL;
                businessParticipant.DisplayName = Parameter.CompanyName;
                businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();
                businessParticipant.IfTenant_Tenant_RefID = customerTenant.CMN_TenantID;
                businessParticipant.IsCompany             = true;
                businessParticipant.IsTenant           = true;
                businessParticipant.Tenant_RefID       = securityTicket.TenantID;
                businessParticipant.Creation_Timestamp = DateTime.Now;
                if (businessParticipant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create CompanyInfo
            var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo.Query()
            {
                CMN_COM_CompanyInfoID = businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID,
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false
            }).SingleOrDefault();

            if (companyInfo == default(ORM_CMN_COM_CompanyInfo))
            {
                companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.CMN_COM_CompanyInfoID = businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfo.Contact_UCD_RefID     = Guid.NewGuid();
                companyInfo.Tenant_RefID          = securityTicket.TenantID;
                companyInfo.Creation_Timestamp    = DateTime.Now;
                if (companyInfo.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create UniversalContactDetails for Tenant and CompanyInfo
            var ucdTenant = ORM_CMN_UniversalContactDetail.Query.Search(
                Connection,
                Transaction,
                new ORM_CMN_UniversalContactDetail.Query()
            {
                CMN_UniversalContactDetailID = customerTenant.UniversalContactDetail_RefID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (ucdTenant == default(ORM_CMN_UniversalContactDetail))
            {
                ucdTenant = new ORM_CMN_UniversalContactDetail();
                ucdTenant.CMN_UniversalContactDetailID = customerTenant.UniversalContactDetail_RefID;
                ucdTenant.UniversalContactDetailsITL   = Parameter.TenantUniversalContactDetailITL;
                ucdTenant.IsCompany          = true;
                ucdTenant.CompanyName_Line1  = Parameter.CompanyName;
                ucdTenant.Contact_Email      = Parameter.ContactEmail;
                ucdTenant.Tenant_RefID       = securityTicket.TenantID;
                ucdTenant.Creation_Timestamp = DateTime.Now;
                if (ucdTenant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }

            var ucdCompanyInfo = ORM_CMN_UniversalContactDetail.Query.Search(
                Connection,
                Transaction,
                new ORM_CMN_UniversalContactDetail.Query()
            {
                CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (ucdCompanyInfo == default(ORM_CMN_UniversalContactDetail))
            {
                ucdCompanyInfo = new ORM_CMN_UniversalContactDetail();
                ucdCompanyInfo.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                ucdCompanyInfo.UniversalContactDetailsITL   = Parameter.CompanyInfoUniversalContactDetailITL;
                ucdCompanyInfo.IsCompany          = true;
                ucdCompanyInfo.CompanyName_Line1  = Parameter.CompanyName;
                ucdCompanyInfo.Contact_Email      = Parameter.ContactEmail;
                ucdCompanyInfo.Tenant_RefID       = securityTicket.TenantID;
                ucdCompanyInfo.Creation_Timestamp = DateTime.Now;
                if (ucdCompanyInfo.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            returnValue.Result.TenantID = customerTenant.CMN_TenantID;
            returnValue.Result.BusinessParticipantID               = businessParticipant.CMN_BPT_BusinessParticipantID;
            returnValue.Result.TenantUniversalContactDetailID      = ucdTenant.CMN_UniversalContactDetailID;
            returnValue.Result.CompanyInfoUniversalContactDetailID = ucdCompanyInfo.CMN_UniversalContactDetailID;
            returnValue.Result.CompanyInfoID = companyInfo.CMN_COM_CompanyInfoID;
            returnValue.Status = FR_Status.Success;

            return(returnValue);

            #endregion UserCode
        }
Beispiel #18
0
        protected static FR_L5EM_GEFU_445 Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var           returnValue = new FR_L5EM_GEFU_445();
            L5EM_GEFU_445 result      = new L5EM_GEFU_445();


            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);
            if (account.USR_AccountID == Guid.Empty)
            {
                return(null);
            }

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            employeeQuery.BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);
            if (employeeList.Count != 0)
            {
                ORM_CMN_BPT_EMP_Employee employee = employeeList[0];
                result.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
                result.Staff_Number           = employee.Staff_Number;
                result.StandardFunction       = employee.StandardFunction;


                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GEFU_445_EmployeeWorkplaceHistory>       employeeWorkplaceAssignments     = new List <L5EM_GEFU_445_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GEFU_445_EmployeeWorkplaceHistory item = new L5EM_GEFU_445_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();
            }
            returnValue.Result = result;
            //Put your code here
            return(returnValue);

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

            returnValue.Result = new L5RS_CSaRSPfH_0449();
            FR_Base resultHeader, resultPosition, resultReturnPosition;

            if (Parameter.Positions.Count() <= 0)
            {
                returnValue.Status = FR_Status.Success;
                returnValue.Result = null;
                return(returnValue);
            }

            #region Load Shipment Header and calculate Total Price
            decimal totalValueWithoutTax = 0;

            #region Load Shipment Header
            var shipmentHeader = new ORM_LOG_SHP_Shipment_Header();
            var result         = shipmentHeader.Load(Connection, Transaction, Parameter.Positions[0].ShipmentHeaderID);
            if (result.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = null;
                return(returnValue);
            }
            #endregion

            #region Load Shipment Header Positions And Calculate Total Value
            var shipmentPositions = ORM_LOG_SHP_Shipment_Position.Query.Search(
                Connection,
                Transaction,
                new ORM_LOG_SHP_Shipment_Position.Query()
            {
                LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID,
                Tenant_RefID = securityTicket.TenantID
            }).ToList();
            foreach (var position in shipmentPositions)
            {
                totalValueWithoutTax += position.ShipmentPosition_ValueWithoutTax;
            }
            #endregion

            shipmentHeader.ShipmentHeader_ValueWithoutTax = totalValueWithoutTax;
            #endregion

            var resultShipmentPositionsIDs      = new List <Guid>();
            var resultReturnShipmentPositionIDs = new List <Guid>();
            foreach (P_L5RS_CSaRSPfH_0449a position in Parameter.Positions)
            {
                #region Create Shipment Position Object
                var newShipmentPositionObject = new ORM_LOG_SHP_Shipment_Position();
                newShipmentPositionObject.CMN_PRO_Product_RefID         = position.ProductId;
                newShipmentPositionObject.Creation_Timestamp            = DateTime.Now;
                newShipmentPositionObject.LOG_SHP_Shipment_Header_RefID = position.ShipmentHeaderID;
                newShipmentPositionObject.LOG_SHP_Shipment_PositionID   = Guid.NewGuid();
                newShipmentPositionObject.QuantityToShip = position.Quantity;
                newShipmentPositionObject.ShipmentPosition_ValueWithoutTax             = position.PricePerUnit * position.Quantity;
                newShipmentPositionObject.ShipmentPosition_PricePerUnitValueWithoutTax = position.PricePerUnit;
                newShipmentPositionObject.Tenant_RefID         = securityTicket.TenantID;
                shipmentHeader.ShipmentHeader_ValueWithoutTax += newShipmentPositionObject.ShipmentPosition_ValueWithoutTax;
                #endregion

                #region Create ReturnShipment Position Object
                var newReturnShipmentPositionObject = new ORM_LOG_SHP_ReturnShipment_Position();
                newReturnShipmentPositionObject.Creation_Timestamp                = DateTime.Now;
                newReturnShipmentPositionObject.Ext_Shipment_Position_RefID       = newShipmentPositionObject.LOG_SHP_Shipment_PositionID;
                newReturnShipmentPositionObject.LOG_SHP_ReturnShipment_PositionID = Guid.NewGuid();
                newReturnShipmentPositionObject.ReturnPolicy_RefID                = position.ReturnPolicyId;
                newReturnShipmentPositionObject.ReturnProductOriginatedFromReceiptPosition_RefID = position.ReceiptPositionId;
                newReturnShipmentPositionObject.ReturnShipment_Header_RefID = position.ReturnShipmentHeaderID;
                newReturnShipmentPositionObject.Tenant_RefID = securityTicket.TenantID;
                #endregion

                #region Save Position
                resultPosition       = newShipmentPositionObject.Save(Connection, Transaction);
                resultReturnPosition = newReturnShipmentPositionObject.Save(Connection, Transaction);
                if (resultPosition.Status != FR_Status.Success || resultReturnPosition.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = null;
                    return(returnValue);
                }
                resultShipmentPositionsIDs.Add(newShipmentPositionObject.LOG_SHP_Shipment_PositionID);
                resultReturnShipmentPositionIDs.Add(newReturnShipmentPositionObject.LOG_SHP_ReturnShipment_PositionID);
                #endregion
            }

            #region Update Shipment Header with Total Value
            resultHeader = shipmentHeader.Save(Connection, Transaction);
            if (resultHeader.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = null;
                return(returnValue);
            }
            #endregion

            #region Fetch ShipmentHeader SupplierName
            var supplierBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
            supplierBusinessParticipant.Load(Connection, Transaction, shipmentHeader.RecipientBusinessParticipant_RefID);
            #endregion

            returnValue.Status = FR_Status.Success;
            returnValue.Result.ShipmentPositionIDs        = resultShipmentPositionsIDs.ToArray();
            returnValue.Result.ReturnShipmentPositionIDs  = resultReturnShipmentPositionIDs.ToArray();
            returnValue.Result.ShipmentHeaderSupplierName = supplierBusinessParticipant == null
                    ? string.Empty : supplierBusinessParticipant.DisplayName;
            returnValue.Result.ShipmentHeaderNumber     = shipmentHeader.ShipmentHeader_Number;
            returnValue.Result.ShipmentHeaderTotalValue = shipmentHeader.ShipmentHeader_ValueWithoutTax;

            return(returnValue);

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


            P_L6DR_DDBID_1653 param = new P_L6DR_DDBID_1653();
            param.CMN_BPT_BusinessParticipantID = Parameter.CMN_BPT_BusinessParticipantID;

            var drivers = cls_Retrieve_Driver_Info_and_VerCode.Invoke(Connection, Transaction, securityTicket).Result;

            var driver = drivers.FirstOrDefault(x => x.CMN_BPT_BusinessParticipantID == param.CMN_BPT_BusinessParticipantID);

            if (driver != null)
            {
                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                if (driver.CMN_PER_PersonInfoID != Guid.Empty)
                {
                    var result = person.Load(Connection, Transaction, driver.CMN_PER_PersonInfoID);
                    if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    person.IsDeleted = true;
                    person.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    var result = bParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipantID);
                    if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    bParticipant.IsDeleted = true;
                    bParticipant.Save(Connection, Transaction);
                }

                if (driver.Contacts != null)
                {
                    foreach (var parContact in driver.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                        if (parContact.CMN_PER_CommunicationContact_TypeID != Guid.Empty)
                        {
                            var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContact_TypeID);
                            if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                            {
                                var error = new FR_Guid();
                                error.ErrorMessage = "No Such ID";
                                error.Status       = FR_Status.Error_Internal;
                                return(error);
                            }
                            contact.IsDeleted = true;
                            contact.Save(Connection, Transaction);
                        }
                    }
                }

                ORM_CMN_Address adress = new ORM_CMN_Address();
                if (driver.CMN_AddressID != Guid.Empty)
                {
                    var result = adress.Load(Connection, Transaction, driver.CMN_AddressID);
                    if (result.Status != FR_Status.Success || adress.CMN_AddressID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    adress.IsDeleted = true;
                    adress.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();
                if (driver.CMN_BPT_SupplierID != Guid.Empty)
                {
                    var result = supplier.Load(Connection, Transaction, driver.CMN_BPT_SupplierID);
                    if (result.Status != FR_Status.Success || supplier.CMN_BPT_SupplierID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    supplier.IsDeleted = true;
                    supplier.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant asossBParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = asossBParticipant.Load(Connection, Transaction, driver.AssociatedBusinessParticipant_RefID);
                    if (result.Status != FR_Status.Success || asossBParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    asossBParticipant.IsDeleted = true;
                    asossBParticipant.Save(Connection, Transaction);
                }


                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant BusinessParticipant_AssociatedBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = BusinessParticipant_AssociatedBusinessParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID);
                    if (result.Status != FR_Status.Success || BusinessParticipant_AssociatedBusinessParticipant.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    BusinessParticipant_AssociatedBusinessParticipant.IsDeleted = true;
                    BusinessParticipant_AssociatedBusinessParticipant.Save(Connection, Transaction);
                }

                ORM_USR_Account account = new ORM_USR_Account();
                if (driver.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, driver.USR_AccountID);
                    if (result.Status != FR_Status.Success || account.USR_AccountID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    account.IsDeleted = true;
                    account.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                if (driver.USR_Device_AccountCode_UsageHistoryID != Guid.Empty)
                {
                    var result = Device_AccountCode_StatusHistory.Load(Connection, Transaction, driver.USR_Device_AccountCode_UsageHistoryID);
                    if (result.Status != FR_Status.Success || Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    Device_AccountCode_StatusHistory.IsDeleted = true;
                    Device_AccountCode_StatusHistory.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                if (driver.USR_Device_AccountCodeID != Guid.Empty)
                {
                    var result = accountCode.Load(Connection, Transaction, driver.USR_Device_AccountCodeID);
                    if (result.Status != FR_Status.Success || accountCode.USR_Device_AccountCodeID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    accountCode.IsDeleted = true;
                    accountCode.Save(Connection, Transaction);
                }

                var Device_AccountCode_UsageHistoryQuery = new ORM_USR_Device_AccountCode_UsageHistory.Query();
                Device_AccountCode_UsageHistoryQuery.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_UsageHistoryQuery.IsDeleted    = false;
                Device_AccountCode_UsageHistoryQuery.Tenant_RefID = securityTicket.TenantID;

                var historyArray = ORM_USR_Device_AccountCode_UsageHistory.Query.Search(Connection, Transaction, Device_AccountCode_UsageHistoryQuery);
                if (historyArray != null && historyArray.Count > 0)
                {
                    foreach (var historyItem in historyArray)
                    {
                        historyItem.IsDeleted = true;
                        historyItem.Save(Connection, Transaction);
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }
Beispiel #21
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_SD_1537 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            if (Parameter.CMN_BPT_BusinessParticipantID == Guid.Empty)
            {
                #region Create Mode

                #region BusinessParticipant


                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                bParticipant.IsNaturalPerson    = true;
                bParticipant.Tenant_RefID       = securityTicket.TenantID;
                bParticipant.Creation_Timestamp = DateTime.Now;
                bParticipant.Save(Connection, Transaction);

                #endregion

                #region Account

                ORM_USR_Account account = new ORM_USR_Account();

                account.Username    = Parameter.FirstName + "_" + Parameter.LastName;
                account.AccountType = 3;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID       = securityTicket.TenantID;
                account.Creation_Timestamp = DateTime.Now;
                account.Save(Connection, Transaction);

                P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505();
                codeParam.codeLength = 8;
                var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result;

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                accountCode.Account_RefID                   = account.USR_AccountID;
                accountCode.AccountCode_Value               = checkCodeValue.CodeValue;
                accountCode.AccountCode_ValidFrom           = DateTime.Now;
                accountCode.AccountCode_CurrentStatus_RefID = Guid.NewGuid();
                accountCode.IsAccountCode_Expirable         = false;
                accountCode.Tenant_RefID       = securityTicket.TenantID;
                accountCode.Creation_Timestamp = DateTime.Now;
                accountCode.Save(Connection, Transaction);

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID = accountCode.AccountCode_CurrentStatus_RefID;
                Device_AccountCode_StatusHistory.IsAccountCode_Active     = true;
                Device_AccountCode_StatusHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_StatusHistory.Tenant_RefID             = securityTicket.TenantID;
                Device_AccountCode_StatusHistory.Creation_Timestamp       = DateTime.Now;
                Device_AccountCode_StatusHistory.Save(Connection, Transaction);


                ORM_USR_Device_AccountCode_UsageHistory USR_Device_AccountCode_UsageHistory = new ORM_USR_Device_AccountCode_UsageHistory();
                USR_Device_AccountCode_UsageHistory.USR_Device_AccountCode_UsageHistoryID = Guid.NewGuid();
                USR_Device_AccountCode_UsageHistory.Tenant_RefID             = securityTicket.TenantID;
                USR_Device_AccountCode_UsageHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                USR_Device_AccountCode_UsageHistory.Creation_Timestamp       = DateTime.Now;
                USR_Device_AccountCode_UsageHistory.Save(Connection, Transaction);


                #endregion

                #region PersonInfo and Adresses

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Salutation_General   = Parameter.Salutation_General;
                personInfo.FirstName            = Parameter.FirstName;
                personInfo.LastName             = Parameter.LastName;
                personInfo.PrimaryEmail         = Parameter.PrimaryMail;
                personInfo.Address_RefID        = Guid.NewGuid();
                personInfo.Tenant_RefID         = securityTicket.TenantID;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_PER_PersonInfo_2_Address personAdress = new ORM_CMN_PER_PersonInfo_2_Address();
                personAdress.AssignmentID             = Guid.NewGuid();
                personAdress.CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                personAdress.CMN_Address_RefID        = personInfo.Address_RefID;
                personAdress.IsPrimary    = true;
                personAdress.Tenant_RefID = securityTicket.TenantID;
                personAdress.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.CMN_AddressID   = personInfo.Address_RefID;
                adress.City_Name       = Parameter.City_Name;
                adress.Province_Name   = Parameter.Province_Name;
                adress.Street_Name     = Parameter.Street_Name;
                adress.Street_Number   = Parameter.Street_Number;
                adress.City_PostalCode = Parameter.City_PostalCode;
                adress.Tenant_RefID    = securityTicket.TenantID;
                adress.Save(Connection, Transaction);

                #endregion

                #region Contacts

                foreach (var parContact in Parameter.Contacts)
                {
                    ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                    contact.Content          = parContact.Content;
                    contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Tenant_RefID     = securityTicket.TenantID;
                    contact.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    contact.Save(Connection, Transaction);
                }

                #endregion

                #region Driver To Employer

                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant bpt_asBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                bpt_asBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                bpt_asBP.BusinessParticipant_RefID          = bParticipant.CMN_BPT_BusinessParticipantID;
                bpt_asBP.AssociatedParticipant_FunctionName = "Driver";
                bpt_asBP.Tenant_RefID = securityTicket.TenantID;
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);

                #endregion

                #endregion
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);

                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                personInfo.Salutation_General = Parameter.Salutation_General;
                personInfo.FirstName          = Parameter.FirstName;
                personInfo.LastName           = Parameter.LastName;
                personInfo.PrimaryEmail       = Parameter.PrimaryMail;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.Load(Connection, Transaction, personInfo.Address_RefID);
                adress.City_Name     = Parameter.City_Name;
                adress.Province_Name = Parameter.Province_Name;
                adress.Street_Name   = Parameter.Street_Name;
                adress.Street_Number = Parameter.Street_Number;
                adress.Save(Connection, Transaction);

                foreach (var parContact in Parameter.Contacts)
                {
                    var query = new ORM_CMN_PER_CommunicationContact.Query();
                    query.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    query.IsDeleted        = false;
                    query.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                    var contact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query).First();
                    contact.Content      = parContact.Content;
                    contact.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Save(Connection, Transaction);
                }

                var associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associationQuery.BusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID;
                associationQuery.IsDeleted = false;

                var bpt_asBP = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery).First();
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);
            }
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5OF_GOFT_1157_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5OF_GOFT_1157_Array();
            ORM_CMN_STR_Office.Query officesQuery = new ORM_CMN_STR_Office.Query();
            officesQuery.IsDeleted    = false;
            officesQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_STR_Office> officesResult     = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officesQuery);
            List <L5OF_GOFT_1157>     officesResultList = new List <L5OF_GOFT_1157>();
            foreach (var office in officesResult)
            {
                L5OF_GOFT_1157 result = new L5OF_GOFT_1157();
                var            item   = new ORM_CMN_STR_Office();

                var resultOffice = item.Load(Connection, Transaction, office.CMN_STR_OfficeID);
                if (resultOffice.Status != FR_Status.Success || item.CMN_STR_OfficeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(null);
                }

                result.CMN_CAL_CalendarInstance_RefID = item.CMN_CAL_CalendarInstance_RefID;
                result.CMN_STR_OfficeID             = item.CMN_STR_OfficeID;
                result.Country_RefID                = item.Country_RefID;
                result.Default_FaxNumber            = item.Default_FaxNumber;
                result.Default_PhoneNumber          = item.Default_PhoneNumber;
                result.Office_ShortName             = item.Office_ShortName;
                result.OfficeDescription            = item.Office_Description;
                result.OfficeName                   = item.Office_Name;
                result.Region_RefID                 = item.Region_RefID;
                result.BillingAddress_CMN_AddressID = item.Default_BillingAddress_RefID;



                var address    = new ORM_CMN_Address();
                var resultItem = address.Load(Connection, Transaction, item.Default_BillingAddress_RefID);
                if (resultItem.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(null);
                }

                result.BillingAddress_City_Name = address.City_Name;
                result.BillingAddress_City_AdministrativeDistrict = address.City_AdministrativeDistrict;
                result.BillingAddress_City_PostalCode             = address.City_PostalCode;
                result.BillingAddress_City_Region     = address.City_Region;
                result.BillingAddress_Country_Name    = address.Country_Name;
                result.BillingAddress_Province_Name   = address.Province_Name;
                result.BillingAddress_Street_Name     = address.Street_Name;
                result.BillingAddress_Street_Number   = address.Street_Number;
                result.BillingAddress_Country_ISOCode = address.Country_ISOCode;



                ORM_CMN_STR_Office_2_CostCenter.Query officeToCostcenterQuery = new  ORM_CMN_STR_Office_2_CostCenter.Query();
                officeToCostcenterQuery.Office_RefID = office.CMN_STR_OfficeID;
                officeToCostcenterQuery.Tenant_RefID = securityTicket.TenantID;
                officeToCostcenterQuery.IsDeleted    = false;
                List <ORM_CMN_STR_Office_2_CostCenter> officeToCostcenterList = ORM_CMN_STR_Office_2_CostCenter.Query.Search(Connection, Transaction, officeToCostcenterQuery);
                if (officeToCostcenterList.Count != 0)
                {
                    L5OF_GOFT_1157_Costcenter costCenter     = new L5OF_GOFT_1157_Costcenter();
                    ORM_CMN_STR_CostCenter    costCenterItem = new ORM_CMN_STR_CostCenter();
                    costCenterItem.Load(Connection, Transaction, officeToCostcenterList[0].CostCenter_RefID);
                    if (!costCenterItem.IsDeleted)
                    {
                        costCenter.AssignmentID         = officeToCostcenterList[0].AssignmentID;
                        costCenter.CMN_STR_CostCenterID = officeToCostcenterList[0].CostCenter_RefID;
                        costCenter.CostcenterName       = costCenterItem.Name;
                        costCenter.InternalID           = costCenterItem.InternalID;
                        result.Costcenter = costCenter;
                    }
                }
                var responsiblePersonsQuery = new ORM_CMN_STR_Office_ResponsiblePerson.Query();
                responsiblePersonsQuery.Tenant_RefID = securityTicket.TenantID;
                responsiblePersonsQuery.Office_RefID = item.CMN_STR_OfficeID;
                responsiblePersonsQuery.IsDeleted    = false;
                var responsiblePersonsList = ORM_CMN_STR_Office_ResponsiblePerson.Query.Search(Connection, Transaction, responsiblePersonsQuery);
                List <L5OF_GOFT_1157_ResponsiblePersons> responsiblePresonsResultList = new List <L5OF_GOFT_1157_ResponsiblePersons>();
                foreach (var responsiblePerson in responsiblePersonsList)
                {
                    L5OF_GOFT_1157_ResponsiblePersons responsiblePersonResult = new L5OF_GOFT_1157_ResponsiblePersons();
                    responsiblePersonResult.CMN_BPT_EMP_EmployeeID             = responsiblePerson.CMN_BPT_EMP_Employee_RefID;
                    responsiblePersonResult.CMN_STR_Office_ResponsiblePersonID = responsiblePerson.CMN_STR_Office_ResponsiblePersonID;

                    ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                    employee.Load(Connection, Transaction, responsiblePerson.CMN_BPT_EMP_Employee_RefID);

                    ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                    bParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                    ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                    person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                    responsiblePersonResult.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
                    responsiblePersonResult.FirstName = person.FirstName;
                    responsiblePersonResult.LastName  = person.LastName;
                    responsiblePresonsResultList.Add(responsiblePersonResult);
                }
                result.Managers = responsiblePresonsResultList.ToArray();
                officesResultList.Add(result);
            }
            returnValue.Result = officesResultList.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Beispiel #23
0
        public static void Save_Doctors_to_DB(Doctor_model_from_xlsx Parameter, string connectionString, SessionSecurityTicket securityTicket)
        {
            DbConnection  Connection         = null;
            DbTransaction Transaction        = null;
            bool          cleanupConnection  = Connection == null;
            bool          cleanupTransaction = Transaction == null;

            if (cleanupConnection == true)
            {
                Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(connectionString);
                Connection.Open();
            }
            if (cleanupTransaction == true)
            {
                Transaction = Connection.BeginTransaction();
            }
            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
                Guid   BusinessParticipantID         = Guid.NewGuid();
                Guid   personInfoID                  = Guid.NewGuid();
                Guid   PracticeCustomerID            = Guid.NewGuid();
                Guid   PracticeBusinessParticipantID = Guid.NewGuid();
                Guid   PracticeCompanyInfoID         = Guid.NewGuid();
                String PracticeName                  = "";
                Guid   BankAccountID                 = Guid.Empty;
                Guid   doctor_id    = Parameter.DoctorID;
                var    isOpPractice = false;

                if (!String.IsNullOrEmpty(Parameter.LoginEmail))
                //uncomment this if you've created account
                //  if (false)
                {
                    string[] stringUser  = Parameter.LoginEmail.Split('@');
                    string   usernameStr = stringUser[0];

                    try
                    {
                        var doctorAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            AccountSignInEmailAddress = Parameter.LoginEmail,
                        }).Single();

                        var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query();
                        accountGroupQuery.Tenant_RefID             = securityTicket.TenantID;
                        accountGroupQuery.IsDeleted                = false;
                        accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";

                        var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault();

                        if (accountGroup == null)
                        {
                            accountGroup = new ORM_USR_Account_FunctionLevelRights_Group();
                            accountGroup.Tenant_RefID             = securityTicket.TenantID;
                            accountGroup.Label                    = "mm.docconect.doc.app.group";
                            accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";
                            accountGroup.Creation_Timestamp       = DateTime.Now;
                            accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid();
                            accountGroup.Save(Connection, Transaction);
                        }

                        var PracticeAccount2UniversalProperty = ORM_HEC_MedicalPractice_2_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_UniversalProperty.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            HEC_MedicalPractice_RefID = Parameter.PracticeID
                        }).ToList();

                        List <ORM_HEC_MedicalPractice_UniversalProperty> PracticeUniversalPropertyList = new List <ORM_HEC_MedicalPractice_UniversalProperty>();
                        foreach (var item in PracticeAccount2UniversalProperty)
                        {
                            var PracticeUniversalProperty = ORM_HEC_MedicalPractice_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_UniversalProperty.Query()
                            {
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID,
                                HEC_MedicalPractice_UniversalPropertyID = item.HEC_MedicalPractice_UniversalProperty_RefID
                            }).Single();
                            PracticeUniversalPropertyList.Add(PracticeUniversalProperty);
                        }
                        ;

                        P_DO_GPAIDfPID_1522 practiceAccountIDParameter = new P_DO_GPAIDfPID_1522();
                        practiceAccountIDParameter.PracticeID = Parameter.PracticeID;

                        var practiceAccountToFunctionLevelRightQ = new ORM_USR_Account_2_FunctionLevelRight.Query();
                        practiceAccountToFunctionLevelRightQ.Account_RefID = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, practiceAccountIDParameter, securityTicket).Result.accountID;
                        practiceAccountToFunctionLevelRightQ.Tenant_RefID  = securityTicket.TenantID;
                        practiceAccountToFunctionLevelRightQ.IsDeleted     = false;

                        var practiceAccountToFunctionLevelRight = ORM_USR_Account_2_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountToFunctionLevelRightQ).SingleOrDefault();

                        if (practiceAccountToFunctionLevelRight != null)
                        {
                            var practiceAccountFunctionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                            practiceAccountFunctionLevelRightQ.Tenant_RefID = securityTicket.TenantID;
                            practiceAccountFunctionLevelRightQ.IsDeleted    = false;
                            practiceAccountFunctionLevelRightQ.USR_Account_FunctionLevelRightID = practiceAccountToFunctionLevelRight.FunctionLevelRight_RefID;

                            var practiceAccountFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, practiceAccountFunctionLevelRightQ).SingleOrDefault();

                            if (practiceAccountFunctionLevelRight != null)
                            {
                                isOpPractice = practiceAccountFunctionLevelRight.GlobalPropertyMatchingID.Equals("mm.docconect.doc.app.op.practice");
                            }
                        }

                        var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                        functionLevelRightQ.Tenant_RefID             = securityTicket.TenantID;
                        functionLevelRightQ.IsDeleted                = false;
                        functionLevelRightQ.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

                        var existingFunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, functionLevelRightQ).SingleOrDefault();

                        var tempFunctionLevelRightID = Guid.Empty;

                        if (existingFunctionLevelRight == null)
                        {
                            ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight();
                            functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid();
                            functionLevelRight.FunctionLevelRights_Group_RefID  = accountGroup.USR_Account_FunctionLevelRights_GroupID;
                            functionLevelRight.Tenant_RefID       = securityTicket.TenantID;
                            functionLevelRight.Creation_Timestamp = DateTime.Now;

                            functionLevelRight.RightName = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";
                            functionLevelRight.GlobalPropertyMatchingID = isOpPractice ? "mm.docconect.doc.app.op.doctor" : "mm.docconect.doc.app.ac.doctor";

                            functionLevelRight.Save(Connection, Transaction);

                            tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID;
                        }
                        else
                        {
                            tempFunctionLevelRightID = existingFunctionLevelRight.USR_Account_FunctionLevelRightID;
                        }

                        var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight();
                        accountToFunctionLevelRight.Tenant_RefID             = securityTicket.TenantID;
                        accountToFunctionLevelRight.Creation_Timestamp       = DateTime.Now;
                        accountToFunctionLevelRight.AssignmentID             = Guid.NewGuid();
                        accountToFunctionLevelRight.Account_RefID            = doctorAccountInfo.USR_AccountID;
                        accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID;

                        accountToFunctionLevelRight.Save(Connection, Transaction);

                        var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();

                        businessParticipantQ.IsDeleted    = false;
                        businessParticipantQ.Tenant_RefID = securityTicket.TenantID;
                        businessParticipantQ.CMN_BPT_BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID;
                        BusinessParticipantID = doctorAccountInfo.BusinessParticipant_RefID;

                        var DoctorBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single();
                        DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                        DoctorBusinessParticipant.DisplayName            = Parameter.FirstName + " " + Parameter.LastNAme;
                        DoctorBusinessParticipant.IsNaturalPerson        = true;
                        DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                        DoctorBusinessParticipant.Save(Connection, Transaction);
                        personInfoID = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;


                        var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                        companyInfoPractice.IsDeleted            = false;
                        companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                        companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                        companyInfoPractice.FirstName            = Parameter.FirstName;
                        companyInfoPractice.LastName             = Parameter.LastNAme;
                        companyInfoPractice.Salutation_General   = Parameter.Salutation;
                        companyInfoPractice.Title = Parameter.Title;
                        companyInfoPractice.Save(Connection, Transaction);

                        var communicationContact = new ORM_CMN_PER_CommunicationContact();
                        communicationContact.IsDeleted              = false;
                        communicationContact.Contact_Type           = Guid.NewGuid();
                        communicationContact.Tenant_RefID           = securityTicket.TenantID;
                        communicationContact.Modification_Timestamp = DateTime.Now;
                        communicationContact.PersonInfo_RefID       = personInfoID;
                        communicationContact.Content = Parameter.Email;
                        communicationContact.Save(Connection, Transaction);
                        Guid CommunicationContactTypeID = communicationContact.Contact_Type;


                        var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactType.IsDeleted    = false;
                        communicationContactType.Tenant_RefID = securityTicket.TenantID;
                        communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                        communicationContactType.Type = "Email";
                        communicationContactType.Save(Connection, Transaction);

                        var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                        communicationContact2.IsDeleted              = false;
                        communicationContact2.Contact_Type           = Guid.NewGuid();
                        communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                        communicationContact2.Modification_Timestamp = DateTime.Now;
                        communicationContact2.PersonInfo_RefID       = personInfoID;
                        communicationContact2.Content = Parameter.Phone;
                        communicationContact2.Save(Connection, Transaction);
                        Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                        var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                        communicationContactType2.IsDeleted    = false;
                        communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                        communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                        communicationContactType2.Type = "Phone";
                        communicationContactType2.Save(Connection, Transaction);

                        var doctor = new ORM_HEC_Doctor();
                        doctor.HEC_DoctorID = Guid.NewGuid();
                        doctor.IsDeleted    = false;
                        doctor.Tenant_RefID = securityTicket.TenantID;
                        doctor.BusinessParticipant_RefID = BusinessParticipantID;
                        doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                        doctor.Account_RefID             = Parameter.account_id;

                        doctor.Save(Connection, Transaction);

                        doctor_id = doctor.HEC_DoctorID;

                        var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                        }).Single();


                        var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                        organizationalunit_Staff.IsDeleted    = false;
                        organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                        organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                        organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                        organizationalunit_Staff.Save(Connection, Transaction);

                        var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                        {
                            IsDeleted              = false,
                            Tenant_RefID           = securityTicket.TenantID,
                            CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                        }).Single();
                        var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                        }).Single();

                        PracticeName = PracticeBusinessParticipant.DisplayName;
                        PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                        PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;

                        if (Parameter.IsUsePracticeBank)
                        {
                            var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                            {
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID,
                                CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                            }).Single();


                            var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            business2bankAccount.IsDeleted    = false;
                            business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                            business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                            business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                            business2bankAccount.Creation_Timestamp = DateTime.Now;
                            business2bankAccount.Save(Connection, Transaction);

                            BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                            //end of save bank data if inherited from practice
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                            {
                                var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                                business2bankAccount.IsDeleted    = false;
                                business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                                business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                                business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                                business2bankAccount.Creation_Timestamp = DateTime.Now;
                                business2bankAccount.Save(Connection, Transaction);

                                var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                                bankAccountDoctor.IsDeleted             = false;
                                bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                                bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                                bankAccountDoctor.OwnerText             = Parameter.AccountHolder;
                                bankAccountDoctor.IBAN               = Parameter.IBAN;
                                bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                                bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                                bankAccountDoctor.Save(Connection, Transaction);

                                if (!String.IsNullOrEmpty(Parameter.Bank))
                                {
                                    var bank = new ORM_ACC_BNK_Bank();
                                    bank.IsDeleted          = false;
                                    bank.Tenant_RefID       = securityTicket.TenantID;
                                    bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                                    bank.BICCode            = Parameter.Bic;
                                    bank.BankName           = Parameter.Bank;
                                    bank.Creation_Timestamp = DateTime.Now;
                                    bank.Save(Connection, Transaction);
                                }

                                BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                                // end save bank data
                            }
                        }
                    }
                    catch
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    var DoctorBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();

                    DoctorBusinessParticipant.IsDeleted    = false;
                    DoctorBusinessParticipant.Tenant_RefID = securityTicket.TenantID;
                    DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                    DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                    DoctorBusinessParticipant.DisplayName            = Parameter.FirstName + " " + Parameter.LastNAme;
                    DoctorBusinessParticipant.IsNaturalPerson        = true;
                    DoctorBusinessParticipant.Modification_Timestamp = DateTime.Now;
                    DoctorBusinessParticipant.Save(Connection, Transaction);
                    personInfoID          = DoctorBusinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    BusinessParticipantID = DoctorBusinessParticipant.CMN_BPT_BusinessParticipantID;

                    var companyInfoPractice = new ORM_CMN_PER_PersonInfo();
                    companyInfoPractice.IsDeleted            = false;
                    companyInfoPractice.Tenant_RefID         = securityTicket.TenantID;
                    companyInfoPractice.CMN_PER_PersonInfoID = personInfoID;
                    companyInfoPractice.FirstName            = Parameter.FirstName;
                    companyInfoPractice.LastName             = Parameter.LastNAme;
                    companyInfoPractice.Salutation_General   = Parameter.Salutation;
                    companyInfoPractice.Title = Parameter.Title;
                    companyInfoPractice.Save(Connection, Transaction);

                    var communicationContact = new ORM_CMN_PER_CommunicationContact();
                    communicationContact.IsDeleted              = false;
                    communicationContact.Contact_Type           = Guid.NewGuid();
                    communicationContact.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact.Modification_Timestamp = DateTime.Now;
                    communicationContact.PersonInfo_RefID       = personInfoID;
                    communicationContact.Content = Parameter.Email;
                    communicationContact.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID = communicationContact.Contact_Type;

                    var communicationContactType = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType.IsDeleted    = false;
                    communicationContactType.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID;
                    communicationContactType.Type = "Email";
                    communicationContactType.Save(Connection, Transaction);

                    var communicationContact2 = new ORM_CMN_PER_CommunicationContact();
                    communicationContact2.IsDeleted              = false;
                    communicationContact2.Contact_Type           = Guid.NewGuid();
                    communicationContact2.Tenant_RefID           = securityTicket.TenantID;
                    communicationContact2.Modification_Timestamp = DateTime.Now;
                    communicationContact2.PersonInfo_RefID       = personInfoID;
                    communicationContact2.Content = Parameter.Phone;
                    communicationContact2.Save(Connection, Transaction);
                    Guid CommunicationContactTypeID2 = communicationContact2.Contact_Type;


                    var communicationContactType2 = new ORM_CMN_PER_CommunicationContact_Type();
                    communicationContactType2.IsDeleted    = false;
                    communicationContactType2.Tenant_RefID = securityTicket.TenantID;
                    communicationContactType2.CMN_PER_CommunicationContact_TypeID = CommunicationContactTypeID2;
                    communicationContactType2.Type = "Phone";
                    communicationContactType2.Save(Connection, Transaction);

                    var doctor = new ORM_HEC_Doctor();
                    doctor.HEC_DoctorID = Guid.NewGuid();
                    doctor.IsDeleted    = false;
                    doctor.Tenant_RefID = securityTicket.TenantID;
                    doctor.BusinessParticipant_RefID = BusinessParticipantID;
                    doctor.DoctorIDNumber            = Parameter.LANR.ToString();
                    doctor.Account_RefID             = Parameter.account_id;

                    doctor.Save(Connection, Transaction);

                    doctor_id = doctor.HEC_DoctorID;

                    var ogranizationUnitPractice = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        IfMedicalPractise_HEC_MedicalPractice_RefID = Parameter.PracticeID
                    }).Single();


                    var organizationalunit_Staff = new ORM_CMN_BPT_CTM_OrganizationalUnit_Staff();
                    organizationalunit_Staff.IsDeleted    = false;
                    organizationalunit_Staff.Tenant_RefID = securityTicket.TenantID;
                    organizationalunit_Staff.BusinessParticipant_RefID = BusinessParticipantID;
                    organizationalunit_Staff.OrganizationalUnit_RefID  = ogranizationUnitPractice.CMN_BPT_CTM_OrganizationalUnitID;
                    organizationalunit_Staff.Save(Connection, Transaction);


                    var CustomerPRactice = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
                    {
                        IsDeleted              = false,
                        Tenant_RefID           = securityTicket.TenantID,
                        CMN_BPT_CTM_CustomerID = ogranizationUnitPractice.Customer_RefID
                    }).Single();
                    var PracticeBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_BPT_BusinessParticipantID = CustomerPRactice.Ext_BusinessParticipant_RefID
                    }).Single();
                    PracticeName = PracticeBusinessParticipant.DisplayName;
                    PracticeBusinessParticipantID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID;
                    PracticeCompanyInfoID         = PracticeBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                    if (Parameter.IsUsePracticeBank == true)
                    {
                        var PracticeBusinessParticipant2bankaccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipant_RefID = PracticeBusinessParticipant.CMN_BPT_BusinessParticipantID,
                        }).Single();


                        var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                        business2bankAccount.IsDeleted    = false;
                        business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                        business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                        business2bankAccount.ACC_BNK_BankAccount_RefID         = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        business2bankAccount.Creation_Timestamp = DateTime.Now;
                        business2bankAccount.Save(Connection, Transaction);

                        BankAccountID = PracticeBusinessParticipant2bankaccount.ACC_BNK_BankAccount_RefID;
                        //end of save bank data if inherited from practice
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(Parameter.IBAN) || !String.IsNullOrEmpty(Parameter.Bank))
                        {
                            var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            business2bankAccount.IsDeleted    = false;
                            business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                            business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                            business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                            business2bankAccount.Creation_Timestamp = DateTime.Now;
                            business2bankAccount.Save(Connection, Transaction);

                            var bankAccountDoctor = new ORM_ACC_BNK_BankAccount();
                            bankAccountDoctor.IsDeleted             = false;
                            bankAccountDoctor.Tenant_RefID          = securityTicket.TenantID;
                            bankAccountDoctor.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            bankAccountDoctor.OwnerText             = Parameter.AccountHolder;
                            bankAccountDoctor.IBAN               = Parameter.IBAN;
                            bankAccountDoctor.Bank_RefID         = Guid.NewGuid();
                            bankAccountDoctor.Creation_Timestamp = DateTime.Now;
                            bankAccountDoctor.Save(Connection, Transaction);

                            if (!String.IsNullOrEmpty(Parameter.Bank))
                            {
                                var bank = new ORM_ACC_BNK_Bank();
                                bank.IsDeleted          = false;
                                bank.Tenant_RefID       = securityTicket.TenantID;
                                bank.ACC_BNK_BankID     = bankAccountDoctor.Bank_RefID;
                                bank.BICCode            = Parameter.Bic;
                                bank.BankName           = Parameter.Bank;
                                bank.Creation_Timestamp = DateTime.Now;
                                bank.Save(Connection, Transaction);
                            }

                            BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                            // end save bank data
                        }
                    }
                }
                var PracticeCompanyInfoAddress = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo_Address.Query()
                {
                    IsDeleted           = false,
                    Tenant_RefID        = securityTicket.TenantID,
                    CompanyInfo_RefID   = PracticeCompanyInfoID,
                    Address_Description = "Standard address for billing, shipping",
                }).SingleOrDefault();



                Practice_Doctors_Model DPModel = new Practice_Doctors_Model();

                if (PracticeCompanyInfoAddress != null)
                {
                    var PracticeUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_UniversalContactDetailID = PracticeCompanyInfoAddress.Address_UCD_RefID,
                    }).SingleOrDefault();
                    DPModel.address = PracticeUCD.Street_Name + " " + PracticeUCD.Street_Number;
                    DPModel.zip     = PracticeUCD.ZIP;
                    DPModel.city    = PracticeUCD.Town;
                }

                DPModel.account_status = "aktiv";
                DPModel.id             = doctor_id.ToString();

                var title = string.IsNullOrEmpty(Parameter.Title) ? "" : Parameter.Title.Trim();

                DPModel.name              = title + " " + Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.name_untouched    = Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.bsnr_lanr         = Parameter.LANR.ToString();
                DPModel.autocomplete_name = title + " " + Parameter.FirstName + " " + Parameter.LastNAme;
                DPModel.salutation        = title;

                DPModel.type = "Doctor";

                DPModel.bank = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;

                DPModel.bank_untouched = string.IsNullOrEmpty(Parameter.Bank) ? "" : Parameter.Bank;


                DPModel.phone = Parameter.Phone;

                DPModel.email = string.IsNullOrEmpty(Parameter.Email) ? "" : Parameter.Email;

                DPModel.iban = string.IsNullOrEmpty(Parameter.IBAN) ? "" : Parameter.IBAN;

                DPModel.bic = string.IsNullOrEmpty(Parameter.Bic) ? "" : Parameter.Bic;

                DPModel.bank_id             = BankAccountID.ToString();
                DPModel.bank_info_inherited = Parameter.IsUsePracticeBank;
                DPModel.aditional_info      = "";
                DPModel.contract            = 0;


                DPModel.tenantid = securityTicket.TenantID.ToString();
                DPModel.practice_name_for_doctor = PracticeName;
                DPModel.practice_for_doctor_id   = Parameter.PracticeID.ToString();

                DPModel.role = isOpPractice ? "op" : "ac";

                List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>();
                DPModelL.Add(DPModel);

                Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString());

                #region Assignment to Contract

                var contractIvi = ORM_CMN_CTR_Contract.Query.Search(Connection, Transaction, new ORM_CMN_CTR_Contract.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    ContractName = "IVI-Vertrag"
                }).SingleOrDefault();
                if (contractIvi != null)
                {
                    Guid AssignmentID = Guid.NewGuid();
                    var  insuranceTobrokerContract = ORM_HEC_CRT_InsuranceToBrokerContract.Query.Search(Connection, Transaction, new ORM_HEC_CRT_InsuranceToBrokerContract.Query()
                    {
                        Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false,
                    }).SingleOrDefault();
                    if (insuranceTobrokerContract != null)
                    {
                        AssignmentID = insuranceTobrokerContract.HEC_CRT_InsuranceToBrokerContractID;
                    }
                    else
                    {
                        var insuranceTobrokerContractNew = new ORM_HEC_CRT_InsuranceToBrokerContract();
                        insuranceTobrokerContractNew.HEC_CRT_InsuranceToBrokerContractID = Guid.NewGuid();
                        insuranceTobrokerContractNew.Creation_Timestamp         = DateTime.Now;
                        insuranceTobrokerContractNew.IsDeleted                  = false;
                        insuranceTobrokerContractNew.Tenant_RefID               = securityTicket.TenantID;
                        insuranceTobrokerContractNew.Ext_CMN_CTR_Contract_RefID = contractIvi.CMN_CTR_ContractID;
                        insuranceTobrokerContractNew.Save(Connection, Transaction);
                        AssignmentID = insuranceTobrokerContractNew.HEC_CRT_InsuranceToBrokerContractID;
                    }
                    var insuranceTobrokerContract2doctor = new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingDoctor();
                    insuranceTobrokerContract2doctor.Creation_Timestamp = DateTime.Now;
                    insuranceTobrokerContract2doctor.HEC_CRT_InsuranceToBrokerContract_ParticipatingDoctorID = Guid.NewGuid();
                    insuranceTobrokerContract2doctor.InsuranceToBrokerContract_RefID = AssignmentID;
                    insuranceTobrokerContract2doctor.Tenant_RefID = securityTicket.TenantID;
                    insuranceTobrokerContract2doctor.IsDeleted    = false;
                    insuranceTobrokerContract2doctor.Doctor_RefID = doctor_id;
                    insuranceTobrokerContract2doctor.ValidFrom    = new DateTime(2013, 6, 15);
                    insuranceTobrokerContract2doctor.ValidThrough = DateTime.MinValue;
                    insuranceTobrokerContract2doctor.Save(Connection, Transaction);

                    P_DO_CDCD_1505 ParameterDoctorID = new P_DO_CDCD_1505();
                    ParameterDoctorID.DoctorID = doctor_id;
                    var data = cls_Get_Doctor_Contract_Numbers.Invoke(Connection, Transaction, ParameterDoctorID, securityTicket).Result;

                    int DoctorContracts = data.Count();
                    Doctor_Contracts ParameterDoctor = new Doctor_Contracts();
                    ParameterDoctor.DocID = doctor_id;

                    Practice_Doctors_Model DoctorFound = Get_Doctors_for_PracticeID.Set_Contract_Number_for_DoctorID(ParameterDoctor, securityTicket);

                    if (DoctorFound != null)
                    {
                        List <Practice_Doctors_Model> DoctorFoundL = new List <Practice_Doctors_Model>();
                        DoctorFound.contract = DoctorContracts;
                        DoctorFoundL.Add(DoctorFound);
                        Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DoctorFoundL, securityTicket.TenantID.ToString());
                    }


                    P_DO_GPIDfDID_1353 ParametarDocID = new P_DO_GPIDfDID_1353();
                    ParametarDocID.DoctorID = doctor_id;
                    DO_GPIDfDID_1353[] data2 = cls_Get_PracticeID_for_DoctorID.Invoke(Connection, Transaction, ParametarDocID, securityTicket).Result;

                    P_DO_GCfPID_1507 ParametarPractice = new P_DO_GCfPID_1507();

                    ParametarPractice.PracticeID = data2.First().HEC_MedicalPractiseID;
                    DO_GCfPID_1507[] Contracts       = cls_Get_all_Doctors_Contract_Assignment_for_PracticeID.Invoke(Connection, Transaction, ParametarPractice, securityTicket).Result;
                    int NumberOfContractsForPractice = Contracts.Count();
                    Practice_Doctors_Model practice  = new Practice_Doctors_Model();
                    practice.id = ParametarPractice.PracticeID.ToString();

                    Practice_Doctors_Model        PracticeFound = Get_Doctors_for_PracticeID.Get_Practice_for_PracticeID(practice, securityTicket);
                    List <Practice_Doctors_Model> practiceL     = new List <Practice_Doctors_Model>();
                    PracticeFound.contract = NumberOfContractsForPractice;
                    practiceL.Add(PracticeFound);
                    Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(practiceL, securityTicket.TenantID.ToString());
                }
                #endregion



                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
            }



            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw ex;
            }
        }
Beispiel #24
0
        protected static FR_L6LR_GLR_ID_1339 Execute(DbConnection Connection, DbTransaction Transaction, P_L6LR_GLR_ID_1339 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6LR_GLR_ID_1339();
            returnValue.Result = new L6LR_GLR_ID_1339();


            //Covers
            ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query leaveRequestQuery = new ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query();
            leaveRequestQuery.CMN_BPT_EMP_Employee_LeaveRequestID = Parameter.LeaveID;
            leaveRequestQuery.Tenant_RefID = securityTicket.TenantID;
            leaveRequestQuery.IsDeleted    = false;
            ORM_CMN_BPT_EMP_Employee_LeaveRequest leaveRequest = ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query.Search(Connection, Transaction, leaveRequestQuery).FirstOrDefault();
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            employee.Load(Connection, Transaction, leaveRequest.RequestedFor_Employee_RefID);
            L5LR_GLRFSP_1532 result = new L5LR_GLRFSP_1532();
            result.ForEmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            result.ForEmployee_BusinessParticipant_RefID = employee.BusinessParticipant_RefID;
            result.ForEmployee_Staff_Number     = employee.Staff_Number;
            result.ForEmployee_StandardFunction = employee.StandardFunction;
            result.LeaveRequestCreationSource   = leaveRequest.LeaveRequestCreationSource;
            ORM_CMN_BPT_BusinessParticipant bpart = new ORM_CMN_BPT_BusinessParticipant();
            bpart.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

            ORM_CMN_PER_PersonInfo per = new ORM_CMN_PER_PersonInfo();
            per.Load(Connection, Transaction, bpart.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
            result.FirstName = per.FirstName;
            result.LastName  = per.LastName;

            result.CMN_CAL_Event_RefID          = leaveRequest.CMN_CAL_Event_RefID;
            result.CMN_CAL_Event_Approval_RefID = leaveRequest.CMN_CAL_Event_Approval_RefID;
            //result.AbsenceReason_Type_RefID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID;
            result.Comment = leaveRequest.Comment;
            result.RequestedBy_Employee_RefID          = leaveRequest.RequestedBy_Employee_RefID;
            result.CMN_BPT_EMP_Employee_LeaveRequestID = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID;
            ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover.Query covers = new ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover.Query();
            covers.CMN_BPT_EMP_Employee_LeaveRequests = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID;
            covers.Tenant_RefID = securityTicket.TenantID;
            covers.IsDeleted    = false;
            List <ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover> employeeCovers = ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover.Query.Search(Connection, Transaction, covers);
            result.Cover = new L5LR_GLRFSP_1532_Cover();
            if (employeeCovers.Count != 0)
            {
                ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover employeeCover = employeeCovers[0];
                result.Cover.CMN_BPT_EMP_EmployeeID = employeeCover.EmployeeCover_RefID;
                result.Cover.CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCoverID = employeeCover.CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCoverID;
                result.Cover.SequenceNumber = employeeCover.SequenceNumber;
            }

            ORM_CMN_BPT_STA_AbsenceReason absenceReason = new ORM_CMN_BPT_STA_AbsenceReason();
            absenceReason.Load(Connection, Transaction, leaveRequest.CMN_BPT_STA_AbsenceReason_RefID);

            result.CMN_BPT_STA_AbsenceReason_RefID = absenceReason.CMN_BPT_STA_AbsenceReasonID;
            result.ShortName  = absenceReason.ShortName;
            result.ReasonName = absenceReason.Name;
            result.ReasonDesc = absenceReason.Description;
            result.AbsenceReason_Type_RefID = absenceReason.AbsenceReason_Type_RefID;
            result.ColorCode                            = absenceReason.ColorCode;
            result.Parent_RefID                         = absenceReason.Parent_RefID;
            result.IsAuthorizationRequired              = absenceReason.IsAuthorizationRequired;
            result.IsIncludedInCapacityCalculation      = absenceReason.IsIncludedInCapacityCalculation;
            result.IsAllowedAbsence                     = absenceReason.IsAllowedAbsence;
            result.IsDeactivated                        = absenceReason.IsDeactivated;
            result.IsCarryOverEnabled                   = absenceReason.IsCarryOverEnabled;
            result.IsCaryOverLimited                    = absenceReason.IsCaryOverLimited;
            result.IfCarryOverLimited_MaximumAmount_Hrs = absenceReason.IfCarryOverLimited_MaximumAmount_Hrs;

            ORM_CMN_CAL_Event Event = new ORM_CMN_CAL_Event();
            Event.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_RefID);

            result.CalendarInstance_RefID = Event.CalendarInstance_RefID;
            result.StartTime           = Event.StartTime;
            result.EndTime             = Event.EndTime;
            result.R_EventDuration_sec = Event.R_EventDuration_sec;

            ORM_CMN_CAL_Event_Approval eventApproval = new ORM_CMN_CAL_Event_Approval();
            eventApproval.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_Approval_RefID);

            result.Action = new L5LR_GLRFSP_1532_Action();

            result.IsApproved = eventApproval.IsApproved;
            result.IsApprovalProcessOpened = eventApproval.IsApprovalProcessOpened;
            result.IsApprovalProcessDenied = eventApproval.IsApprovalProcessDenied;

            ORM_CMN_CAL_Event_Approval_Action.Query approvalQuery = new ORM_CMN_CAL_Event_Approval_Action.Query();
            approvalQuery.EventApproval_RefID = eventApproval.CMN_CAL_Event_ApprovalID;
            approvalQuery.Tenant_RefID        = securityTicket.TenantID;
            approvalQuery.IsDeleted           = false;
            List <ORM_CMN_CAL_Event_Approval_Action> apporvalActions = ORM_CMN_CAL_Event_Approval_Action.Query.Search(Connection, Transaction, approvalQuery);
            if (apporvalActions.Count != 0)
            {
                ORM_CMN_CAL_Event_Approval_Action approvalAction = apporvalActions[0];
                result.Action.ActionTriggeredBy_Account_RefID = approvalAction.ActionTriggeredBy_Account_RefID;
                result.Action.CMN_CAL_Event_Approval_ActionID = approvalAction.CMN_CAL_Event_Approval_ActionID;
                result.Action.IsApproval              = approvalAction.IsApproval;
                result.Action.IsRevocation            = approvalAction.IsRevocation;
                result.Action.IsDenial                = approvalAction.IsDenial;
                result.Action.Approval_Action_Commnet = approvalAction.Comment;
            }

            returnValue.Result.Leave = result;
            //Put your code here
            return(returnValue);

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

            var practice = new ORM_HEC_MedicalPractis()
            {
                HEC_MedicalPractiseID = Guid.NewGuid(),
                Tenant_RefID          = securityTicket.TenantID,
                Ext_CompanyInfo_RefID = Guid.NewGuid()
            };
            practice.Save(Connection, Transaction);

            var companyInfo = new ORM_CMN_COM_CompanyInfo()
            {
                CMN_COM_CompanyInfoID           = practice.Ext_CompanyInfo_RefID,
                Tenant_RefID                    = securityTicket.TenantID,
                CompanyInfo_EstablishmentNumber = Parameter.Practice_BSNR
            };
            companyInfo.Save(Connection, Transaction);

            var bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                IsTenant     = true
            }).Single();

            bParticipant.IsCompany = true;
            bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            bParticipant.Save(Connection, Transaction);

            if (Parameter.Doctor != null)
            {
                var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_2_Account.Query()
                {
                    Tenant_RefID      = securityTicket.TenantID,
                    IsDeleted         = false,
                    USR_Account_RefID = Parameter.Doctor.AccountID
                }).Single();

                var query2 = new ORM_CMN_PER_PersonInfo.Query();
                query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID;

                var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query()
                {
                    Tenant_RefID         = securityTicket.TenantID,
                    IsDeleted            = false,
                    CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID
                }).First();

                personInfo.FirstName = Parameter.Doctor.FirstName;
                personInfo.LastName  = Parameter.Doctor.LastName;
                personInfo.Title     = Parameter.Doctor.Title;
                personInfo.Save(Connection, Transaction);

                var bussinessParticipantTable = new ORM_CMN_BPT_BusinessParticipant();
                bussinessParticipantTable.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bussinessParticipantTable.IsNaturalPerson = true;
                bussinessParticipantTable.Tenant_RefID    = securityTicket.TenantID;
                bussinessParticipantTable.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                bussinessParticipantTable.Save(Connection, Transaction);

                var doctor = new ORM_HEC_Doctor();
                doctor.Tenant_RefID = securityTicket.TenantID;
                doctor.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID;
                doctor.Account_RefID             = Parameter.Doctor.AccountID;
                doctor.DoctorIDNumber            = Parameter.Doctor.LANR;
                doctor.Save(Connection, Transaction);

                var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                associatedbusinessparticipants.BusinessParticipant_RefID           = bussinessParticipantTable.CMN_BPT_BusinessParticipantID;
                associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                associatedbusinessparticipants.Tenant_RefID = securityTicket.TenantID;
                associatedbusinessparticipants.Save(Connection, Transaction);

                if (Parameter.Doctor.BankData != null)
                {
                    ORM_CMN_BPT_BusinessParticipant_2_BankAccount bussiness_2_BankaAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                    bussiness_2_BankaAccount.AssignmentID = Guid.NewGuid();
                    bussiness_2_BankaAccount.CMN_BPT_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID;
                    bussiness_2_BankaAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                    bussiness_2_BankaAccount.Tenant_RefID = securityTicket.TenantID;

                    bussiness_2_BankaAccount.Save(Connection, Transaction);

                    ORM_ACC_BNK_BankAccount bankAccount = new ORM_ACC_BNK_BankAccount();

                    bankAccount.ACC_BNK_BankAccountID = bussiness_2_BankaAccount.ACC_BNK_BankAccount_RefID;
                    bankAccount.Tenant_RefID          = securityTicket.TenantID;
                    bankAccount.OwnerText             = Parameter.Doctor.BankData.AccountHolder;
                    bankAccount.AccountNumber         = Parameter.Doctor.BankData.AccountNumber;
                    bankAccount.IBAN       = Parameter.Doctor.BankData.IBAN;
                    bankAccount.Bank_RefID = Guid.NewGuid();

                    bankAccount.Save(Connection, Transaction);

                    ORM_ACC_BNK_Bank bank = new ORM_ACC_BNK_Bank();
                    bank.ACC_BNK_BankID = bankAccount.Bank_RefID;
                    bank.Tenant_RefID   = securityTicket.TenantID;
                    bank.BankName       = Parameter.Doctor.BankData.BankName;
                    bank.BICCode        = Parameter.Doctor.BankData.BIC;
                    bank.BankNumber     = Parameter.Doctor.BankData.BankNumber;

                    bank.Save(Connection, Transaction);
                }
            }

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3CU_CCaMR_1308 Execute(DbConnection Connection, DbTransaction Transaction, P_L3CU_CCaMR_1308 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3CU_CCaMR_1308();
            returnValue.Status = FR_Status.Error_Internal;
            returnValue.Result = new L3CU_CCaMR_1308();

            #region Load or Create Customer Tenant Initial Table Structure
            var customerTenantStructure = cls_Create_Tenant_Initial_Table_Structure.Invoke(
                Connection,
                Transaction,
                new P_L3TE_CTITS_1108()
            {
                TenantITL = Parameter.Customer_TenantITL,
                BusinessParticipantITL               = Parameter.Customer_BusinessParticipantITL,
                TenantUniversalContactDetailITL      = Parameter.Customer_TenantUniversalContactDetailITL,
                CompanyInfoUniversalContactDetailITL = Parameter.Customer_CompanyInfoUniversalContactDetailITL,
                CompanyName  = Parameter.Customer_CompanyName,
                ContactEmail = Parameter.Customer_ContactEmail
            },
                securityTicket);
            #endregion
            if (customerTenantStructure.Status != FR_Status.Success)
            {
                return(returnValue);
            }

            #region Load or Create Customer
            var cust = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query()
            {
                Ext_BusinessParticipant_RefID = customerTenantStructure.Result.BusinessParticipantID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (cust == default(ORM_CMN_BPT_CTM_Customer))
            {
                cust = new ORM_CMN_BPT_CTM_Customer();
                cust.CMN_BPT_CTM_CustomerID        = Guid.NewGuid();
                cust.Ext_BusinessParticipant_RefID = customerTenantStructure.Result.BusinessParticipantID;
                cust.Tenant_RefID       = securityTicket.TenantID;
                cust.Creation_Timestamp = DateTime.Now;
                cust.Save(Connection, Transaction);
            }
            #endregion

            #region Create booking account
            var fiscalYear = cls_Get_Current_FiscalYear.Invoke(Connection, Transaction, securityTicket).Result;

            var bookingAccountParam = new P_L3BA_CCAfBP_1655()
            {
                BusinessParticipantIDs = new Guid[1] {
                    customerTenantStructure.Result.BusinessParticipantID
                },
                FiscalYearID = fiscalYear.ACC_FiscalYearID
            };

            var result = cls_Create_Customer_Account_for_BusinessParticipants.Invoke(Connection, Transaction, bookingAccountParam, securityTicket).Result;
            #endregion

            #region create defaultPerson for customer

            var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            businessParticipantQuery.CMN_BPT_BusinessParticipantID = cust.Ext_BusinessParticipant_RefID;
            businessParticipantQuery.IsDeleted = false;
            var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();

            if (businessParticipant.IsNaturalPerson)
            {
                if (businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID == null || businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID == Guid.Empty)
                {
                    var personInfo = new ORM_CMN_PER_PersonInfo();
                    personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                    personInfo.Tenant_RefID         = securityTicket.TenantID;
                    personInfo.IsDeleted            = false;
                    personInfo.FirstName            = businessParticipant.DisplayName;
                    personInfo.LastName             = businessParticipant.DisplayName;
                    personInfo.Creation_Timestamp   = DateTime.Now;
                    personInfo.Save(Connection, Transaction);

                    businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                }
            }
            else if (businessParticipant.IsCompany)
            {
                Boolean needDefaultPerson = true;
                var     associatedBPQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associatedBPQuery.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                associatedBPQuery.Tenant_RefID = securityTicket.TenantID;
                associatedBPQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant> associations =
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associatedBPQuery);
                if (associations.Count > 0)
                {
                    foreach (var assotiation in associations)
                    {
                        if (assotiation.BusinessParticipant_RefID != Guid.Empty)
                        {
                            ORM_CMN_BPT_BusinessParticipant.Query businessParticipantPersonQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                            businessParticipantPersonQuery.CMN_BPT_BusinessParticipantID = assotiation.BusinessParticipant_RefID;
                            businessParticipantPersonQuery.IsDeleted       = false;
                            businessParticipantPersonQuery.IsNaturalPerson = true;
                            List <ORM_CMN_BPT_BusinessParticipant> businessParticipantsPerson =
                                ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantPersonQuery);
                            foreach (var person in businessParticipantsPerson)
                            {
                                if (person.IfNaturalPerson_CMN_PER_PersonInfo_RefID == Guid.Empty)
                                {
                                    ORM_CMN_PER_PersonInfo personInfoNew = new ORM_CMN_PER_PersonInfo();
                                    personInfoNew.CMN_PER_PersonInfoID = Guid.NewGuid();
                                    personInfoNew.Tenant_RefID         = securityTicket.TenantID;
                                    personInfoNew.IsDeleted            = false;
                                    personInfoNew.FirstName            = person.DisplayName;
                                    personInfoNew.LastName             = person.DisplayName;
                                    personInfoNew.Creation_Timestamp   = DateTime.Now;
                                    personInfoNew.Save(Connection, Transaction);

                                    person.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoNew.CMN_PER_PersonInfoID;
                                }

                                needDefaultPerson = false;
                                break;
                            }
                        }
                    }
                }

                if (needDefaultPerson)
                {
                    #region create personalInfo
                    ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                    personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                    personInfo.Tenant_RefID         = securityTicket.TenantID;
                    personInfo.IsDeleted            = false;
                    personInfo.FirstName            = businessParticipant.DisplayName;
                    personInfo.LastName             = businessParticipant.DisplayName;
                    personInfo.Creation_Timestamp   = DateTime.Now;
                    personInfo.Save(Connection, Transaction);
                    #endregion

                    #region create new businessParticipiant
                    ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                    bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                    bParticipant.Tenant_RefID    = securityTicket.TenantID;
                    bParticipant.IsNaturalPerson = true;
                    bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    bParticipant.DisplayName        = businessParticipant.DisplayName;
                    bParticipant.Creation_Timestamp = DateTime.Now;
                    bParticipant.Save(Connection, Transaction);
                    #endregion

                    #region create associated businessParticipant table
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant associatedBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                    associatedBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                    associatedBP.IsDeleted = false;
                    associatedBP.BusinessParticipant_RefID           = bParticipant.CMN_BPT_BusinessParticipantID;
                    associatedBP.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                    associatedBP.Creation_Timestamp = DateTime.Now;
                    associatedBP.Tenant_RefID       = securityTicket.TenantID;
                    associatedBP.Save(Connection, Transaction);
                    #endregion
                }
            }
            #endregion


            returnValue.Result.Customer_TenantID = customerTenantStructure.Result.TenantID;
            returnValue.Result.Customer_BusinessParticipantID = customerTenantStructure.Result.BusinessParticipantID;
            returnValue.Result.Customer_CompanyInfo_UniversalContactDetailID = customerTenantStructure.Result.CompanyInfoUniversalContactDetailID;
            returnValue.Result.Customer_Tenant_UniversalContactDetailID      = customerTenantStructure.Result.TenantUniversalContactDetailID;
            returnValue.Result.Customer_CustomerID    = cust.CMN_BPT_CTM_CustomerID;
            returnValue.Result.Customer_CompanyInfoID = customerTenantStructure.Result.CompanyInfoID;
            returnValue.Result.IsCustomerOrderAutomaticallyApprovedOnReceipt = cust.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            returnValue.Status = FR_Status.Success;

            return(returnValue);


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

            var doctor = new ORM_HEC_Doctor();

            if (Parameter.DoctorID != Guid.Empty)
            {
                var result = doctor.Load(Connection, Transaction, Parameter.DoctorID);
                if (result.Status != FR_Status.Success || doctor.HEC_DoctorID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                #region Edit

                bool bopAccIsChenged = (doctor.Account_RefID == Parameter.Account_RefID) ? false : true;

                doctor.Account_RefID = Parameter.Account_RefID;
                if (Parameter.isLucentisSave)
                {
                    doctor.DoctorIDNumber = Parameter.ifLucentis_LANR;
                }
                doctor.Save(Connection, Transaction);

                //bussinessParticipant
                var query1 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query1.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID;

                var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First();

                if (!bopAccIsChenged)
                {
                    //personInfo
                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    if (Parameter.isOphthalSave)
                    {
                        personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General;
                        personInfo.Salutation_Letter  = Parameter.ifOphthal_Salutation_Letter;
                    }
                    if (Parameter.isLucentisSave)
                    {
                        personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail;
                    }
                    personInfo.Save(Connection, Transaction);

                    var query4 = new ORM_CMN_PER_CommunicationContact.Query();
                    query4.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                    var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList();

                    if (Parameter.Contacts != null)
                    {
                        foreach (var parContact in Parameter.Contacts)
                        {
                            ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID);
                            if (communicationContacts != null)
                            {
                                communicationContacts.Tenant_RefID = securityTicket.TenantID;
                                communicationContacts.Content      = parContact.Content;
                                communicationContacts.Save(Connection, Transaction);
                            }
                            else
                            {
                                communicationContacts = new ORM_CMN_PER_CommunicationContact();
                                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                                communicationContacts.PersonInfo_RefID   = personInfo.CMN_PER_PersonInfoID;
                                communicationContacts.Contact_Type       = parContact.CMN_PER_CommunicationContact_TypeID;
                                communicationContacts.Content            = parContact.Content;
                                communicationContacts.Creation_Timestamp = DateTime.Now;
                                communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                                communicationContacts.Save(Connection, Transaction);
                            }
                        }
                    }
                }
                else
                {
                    var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID;
                    account2personInfoQuery.Tenant_RefID      = securityTicket.TenantID;
                    account2personInfoQuery.IsDeleted         = false;
                    var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First();

                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    personInfo.Save(Connection, Transaction);

                    var query4 = new ORM_CMN_PER_CommunicationContact.Query();
                    query4.PersonInfo_RefID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                    var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList();

                    if (communicationContactsList != null)
                    {
                        foreach (var c in communicationContactsList)
                        {
                            c.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                            c.Save(Connection, Transaction);
                        }
                    }

                    if (Parameter.Contacts != null)
                    {
                        foreach (var parContact in Parameter.Contacts)
                        {
                            ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID);
                            if (communicationContacts != null)
                            {
                                communicationContacts.Tenant_RefID = securityTicket.TenantID;
                                communicationContacts.Content      = parContact.Content;
                                communicationContacts.Save(Connection, Transaction);
                            }
                            else
                            {
                                communicationContacts = new ORM_CMN_PER_CommunicationContact();
                                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                                communicationContacts.PersonInfo_RefID   = personInfo.CMN_PER_PersonInfoID;
                                communicationContacts.Contact_Type       = parContact.CMN_PER_CommunicationContact_TypeID;
                                communicationContacts.Content            = parContact.Content;
                                communicationContacts.Creation_Timestamp = DateTime.Now;
                                communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                                communicationContacts.Save(Connection, Transaction);
                            }
                        }
                    }

                    bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    bussinessParticipant.Save(Connection, Transaction);
                }
                if (Parameter.isLucentisSave)
                {
                    foreach (var practice in Parameter.Practices)
                    {
                        //if (practice.PracticeID != Guid.Empty) {

                        var medPract = new ORM_HEC_MedicalPractis.Query();
                        medPract.HEC_MedicalPractiseID = practice.PracticeID;

                        var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();

                        var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                        queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;

                        var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();

                        var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                        practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;

                        var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                        var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                        query3.BusinessParticipant_RefID           = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                        query3.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                        query3.IsDeleted = false;

                        var associatedbusinessparticipantsOriginal = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3).FirstOrDefault();
                        if (associatedbusinessparticipantsOriginal != null)
                        {
                            associatedbusinessparticipantsOriginal.IsDeleted = practice.isDeleted;
                            associatedbusinessparticipantsOriginal.Save(Connection, Transaction);
                        }
                        else
                        {
                            var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                            associatedbusinessparticipants.BusinessParticipant_RefID           = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                            associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                            associatedbusinessparticipants.AssociatedParticipant_FunctionName  = practice.AssociatedParticipant_FunctionName;
                            associatedbusinessparticipants.Creation_Timestamp = DateTime.Now;
                            associatedbusinessparticipants.Tenant_RefID       = securityTicket.TenantID;
                            associatedbusinessparticipants.Save(Connection, Transaction);


                            // }
                        }
                    }
                }
                if (Parameter.isOphthalSave && Parameter.Practices.Length == 1)
                {
                    var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                    query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                    query3.IsDeleted = false;
                    var associatedbusinessparticipantsRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3);
                    ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant firstPractice;

                    var medPract = new ORM_HEC_MedicalPractis.Query();
                    medPract.HEC_MedicalPractiseID = Parameter.Practices[0].PracticeID;
                    var medicalPractice  = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();
                    var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                    queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;
                    var companyInfo   = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();
                    var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
                    var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                    if (associatedbusinessparticipantsRes.Count > 0)
                    {
                        associatedbusinessparticipantsRes = associatedbusinessparticipantsRes.OrderBy(a => a.Creation_Timestamp).ToList();
                        firstPractice = associatedbusinessparticipantsRes.First();
                        foreach (var item in associatedbusinessparticipantsRes)
                        {
                            if (item != firstPractice && item.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == practiceBPT.CMN_BPT_BusinessParticipantID)
                            {
                                item.IsDeleted = true;
                                item.Save(Connection, Transaction);
                            }
                        }
                    }
                    else
                    {
                        firstPractice = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                        firstPractice.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                        firstPractice.Tenant_RefID = securityTicket.TenantID;
                        firstPractice.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID;
                    }
                    firstPractice.AssociatedParticipant_FunctionName  = Parameter.Practices[0].AssociatedParticipant_FunctionName;
                    firstPractice.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                    firstPractice.Save(Connection, Transaction);
                }
                #endregion
            }
            else
            {
                #region Save

                //personInfo
                Guid personInfoID;
                if (Parameter.Account_RefID == Guid.Empty)
                {
                    var personInfo = new ORM_CMN_PER_PersonInfo();
                    personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                    personInfo.FirstName            = Parameter.FirstName;
                    personInfo.LastName             = Parameter.LastName;
                    if (Parameter.isLucentisSave)
                    {
                        personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail;
                    }
                    personInfo.Title = Parameter.Title;
                    personInfo.Creation_Timestamp = DateTime.Now;
                    personInfo.Tenant_RefID       = securityTicket.TenantID;
                    if (Parameter.isOphthalSave)
                    {
                        personInfo.Salutation_Letter  = Parameter.ifOphthal_Salutation_Letter;
                        personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General;
                    }
                    personInfo.Save(Connection, Transaction);
                    personInfoID = personInfo.CMN_PER_PersonInfoID;
                }
                else
                {
                    var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID;
                    account2personInfoQuery.Tenant_RefID      = securityTicket.TenantID;
                    account2personInfoQuery.IsDeleted         = false;
                    var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First();

                    var query2 = new ORM_CMN_PER_PersonInfo.Query();
                    query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID;

                    var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();
                    personInfo.FirstName = Parameter.FirstName;
                    personInfo.LastName  = Parameter.LastName;
                    personInfo.Title     = Parameter.Title;
                    personInfo.Save(Connection, Transaction);

                    personInfoID = personInfo.CMN_PER_PersonInfoID;
                }
                //bussinessParticipants
                var bussinessParticipantTable = new ORM_CMN_BPT_BusinessParticipant();
                bussinessParticipantTable.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bussinessParticipantTable.IsNaturalPerson    = true;
                bussinessParticipantTable.IsTenant           = false;
                bussinessParticipantTable.IsCompany          = false;
                bussinessParticipantTable.IsDeleted          = false;
                bussinessParticipantTable.Creation_Timestamp = DateTime.Now;
                bussinessParticipantTable.Tenant_RefID       = securityTicket.TenantID;
                bussinessParticipantTable.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                bussinessParticipantTable.Save(Connection, Transaction);

                doctor.HEC_DoctorID = Guid.NewGuid();
                if (Parameter.isLucentisSave)
                {
                    doctor.DoctorIDNumber = Parameter.ifLucentis_LANR;
                }
                doctor.Creation_Timestamp        = DateTime.Now;
                doctor.Tenant_RefID              = securityTicket.TenantID;
                doctor.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID;
                doctor.Account_RefID             = Parameter.Account_RefID;
                doctor.Save(Connection, Transaction);

                if (Parameter.Contacts != null)
                {
                    foreach (var contact in Parameter.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();
                        communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                        communicationContacts.PersonInfo_RefID   = personInfoID;
                        communicationContacts.Contact_Type       = contact.CMN_PER_CommunicationContact_TypeID;
                        communicationContacts.Content            = contact.Content;
                        communicationContacts.Creation_Timestamp = DateTime.Now;
                        communicationContacts.Tenant_RefID       = securityTicket.TenantID;
                        communicationContacts.Save(Connection, Transaction);
                    }
                }

                foreach (var practice in Parameter.Practices)
                {
                    if (practice.isDeleted == true)
                    {
                        continue;
                    }

                    var medPract = new ORM_HEC_MedicalPractis.Query();
                    medPract.HEC_MedicalPractiseID = practice.PracticeID;
                    var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First();

                    var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                    queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID;
                    var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First();

                    var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                    practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
                    var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First();

                    //associatedbusinessparticipants
                    var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                    associatedbusinessparticipants.BusinessParticipant_RefID           = bussinessParticipantTable.CMN_BPT_BusinessParticipantID;
                    associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID;
                    associatedbusinessparticipants.AssociatedParticipant_FunctionName  = practice.AssociatedParticipant_FunctionName;
                    associatedbusinessparticipants.Creation_Timestamp = DateTime.Now;
                    associatedbusinessparticipants.Tenant_RefID       = securityTicket.TenantID;
                    associatedbusinessparticipants.Save(Connection, Transaction);
                }
                #endregion
            }

            returnValue.Result = doctor.HEC_DoctorID;
            return(returnValue);

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

            var bp = new ORM_CMN_BPT_BusinessParticipant()
            {
                CMN_BPT_BusinessParticipantID = Guid.NewGuid(),
                Tenant_RefID    = securityTicket.TenantID,
                IsNaturalPerson = true,
                IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid(),
                DisplayName = Parameter.Title + " " + Parameter.FirstName + " " + Parameter.LastName
            };
            bp.Save(Connection, Transaction);

            var personInfo = new ORM_CMN_PER_PersonInfo()
            {
                CMN_PER_PersonInfoID = bp.IfNaturalPerson_CMN_PER_PersonInfo_RefID,
                Tenant_RefID         = securityTicket.TenantID,
                Title         = Parameter.Title,
                FirstName     = Parameter.FirstName,
                LastName      = Parameter.LastName,
                PrimaryEmail  = Parameter.Email,
                Address_RefID = Guid.NewGuid()
            };
            personInfo.Save(Connection, Transaction);

            var address = new ORM_CMN_Address()
            {
                CMN_AddressID   = personInfo.Address_RefID,
                Tenant_RefID    = securityTicket.TenantID,
                Street_Name     = Parameter.StreetName,
                Street_Number   = Parameter.StreetNumber,
                City_Name       = Parameter.CityName,
                City_PostalCode = Parameter.CityPostalCode,
                Country_Name    = Parameter.CountryName
            };
            address.Save(Connection, Transaction);

            var bptUser = new ORM_CMN_BPT_USR_User()
            {
                CMN_BPT_USR_UserID        = Guid.NewGuid(),
                Tenant_RefID              = securityTicket.TenantID,
                BusinessParticipant_RefID = bp.CMN_BPT_BusinessParticipantID,
                Username = Parameter.Email
            };

            bptUser.Save(Connection, Transaction);

            var    cryptoUtils = new CryptoUtils();
            string passSalt    = cryptoUtils.GenerateRandomSalt(32);

            var bptUserPass = new ORM_CMN_BPT_USR_User_Password()
            {
                CMN_BPT_USR_User_PasswordID = Guid.NewGuid(),
                CMN_BPT_USR_User_RefID      = bptUser.CMN_BPT_USR_UserID,
                Tenant_RefID       = securityTicket.TenantID,
                Password_Salt      = passSalt,
                Password_Hash      = cryptoUtils.GenerateSaltedHash(Parameter.Password, passSalt),
                Password_Algorithm = cryptoUtils.GetHashAlgorithName(),
                IsActive           = Parameter.IsActivated
            };

            bptUserPass.Save(Connection, Transaction);

            var community = ORM_HEC_CMT_Community.Query.Search(Connection, Transaction, new ORM_HEC_CMT_Community.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                IsCommunityOperatedByThisTenant = true
            }).Single();


            var membershipType = ORM_HEC_CMT_Community_OfferedMembershipType.Query.Search(Connection, Transaction, new ORM_HEC_CMT_Community_OfferedMembershipType.Query()
            {
                Tenant_RefID           = securityTicket.TenantID,
                IsDeleted              = false,
                IsAvailableFor_Tenants = Parameter.IsTenant,
                IsAvailableFor_Doctors = !Parameter.IsTenant
            }).Single();

            var member = new ORM_HEC_CMT_Membership()
            {
                CommunityMembershipITL    = Guid.NewGuid().ToString(),
                HEC_CMT_MembershipID      = Guid.NewGuid(),
                Tenant_RefID              = securityTicket.TenantID,
                Community_RefID           = community.HEC_CMT_CommunityID,
                MembershipType_RefID      = membershipType.HEC_CMT_Community_OfferedMembershipTypeID,
                BusinessParticipant_RefID = bp.CMN_BPT_BusinessParticipantID
            };
            member.Save(Connection, Transaction);

            returnValue.Result = bptUser.CMN_BPT_USR_UserID;

            return(returnValue);

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



            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_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_Name     = Parameter.City_Name;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.Country_Name  = Parameter.Country_Name;
            address.Province_Name = Parameter.Province_Name;
            address.Tenant_RefID  = Parameter.TenantID;
            address.Save(Connection, Transaction);

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

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = Parameter.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.BirthDate     = Parameter.BirthDate;
            person.Save(Connection, Transaction);

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = Parameter.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();


            CSV2Core.DlTrace.Trace("Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = Parameter.TenantID;

            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("after save Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            CSV2Core.DlTrace.Trace("employee.Status_IsAlreadySaved " + employee.Status_IsAlreadySaved);

            ORM_CMN_BPT_EMP_EmploymentRelationship employeeRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_WorkingContractID != Guid.Empty)
            {
                var result = employeeRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_WorkingContractID);
                if (result.Status != FR_Status.Success || employeeRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employeeRelationship.Work_StartDate = Parameter.Work_StartDate;
            employeeRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employeeRelationship.Tenant_RefID   = Parameter.TenantID;
            employeeRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employeeRelationship.Save(Connection, Transaction);



            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, Parameter.USR_AccountID);
                account.USR_AccountID             = Parameter.USR_AccountID;
                account.Username                  = Parameter.username;
                account.DefaultLanguage_RefID     = Parameter.LanguageID;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID              = Parameter.TenantID;
                account.Save(Connection, Transaction);

                var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                personToAccountQuery.IsDeleted         = false;
                var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                if (personToAccounts.Count != 0)
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }

                if (Parameter.Rights != null)
                {
                    foreach (var rightParam in Parameter.Rights)
                    {
                        var right = new ORM_USR_Account_FunctionLevelRight();
                        if (rightParam.RightID != Guid.Empty)
                        {
                            var result = right.Load(Connection, Transaction, rightParam.RightID);
                            if (result.Status != FR_Status.Success || right.USR_Account_FunctionLevelRightID == Guid.Empty)
                            {
                                right.USR_Account_FunctionLevelRightID = rightParam.RightID;
                                right.Tenant_RefID = Parameter.TenantID;
                                right.RightName    = rightParam.RightName;
                                right.FunctionLevelRights_Group_RefID = Guid.Empty;
                                right.Save(Connection, Transaction);
                            }
                        }

                        var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                        right2account.Account_RefID            = account.USR_AccountID;
                        right2account.FunctionLevelRight_RefID = rightParam.RightID;
                        right2account.Tenant_RefID             = Parameter.TenantID;
                        right2account.Save(Connection, Transaction);
                    }
                }
            }

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

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

            #region Retrieving bill header.

            ORM_BIL_BillHeader billHeader     = new ORM_BIL_BillHeader();
            FR_Base            billHeaderLoad = billHeader.Load(Connection, Transaction, Parameter.BillHeaderID);
            if (billHeaderLoad.Status != FR_Status.Success)
            {
                Exception ex = new Exception(billHeaderLoad.ErrorMessage);
                return(new FR_L6BL_GADfBSBR_1010(ex));
            }

            #endregion

            #region Retrieving universal contact details.

            ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
            FR_Base universalContactDetailsLoad = universalContactDetails.Load(Connection, Transaction, billHeader.BillingAddress_UCD_RefID);
            if (universalContactDetailsLoad.Status != FR_Status.Success)
            {
                Exception ex = new Exception(universalContactDetailsLoad.ErrorMessage);
                return(new FR_L6BL_GADfBSBR_1010(ex));
            }

            #endregion

            #region Retrieving business participants details.

            ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
            FR_Base businessParticipantLoad = businessParticipant.Load(Connection, Transaction, billHeader.BillRecipient_BuisnessParticipant_RefID);
            if (businessParticipantLoad.Status != FR_Status.Success)
            {
                Exception ex = new Exception(businessParticipantLoad.ErrorMessage);
                return(new FR_L6BL_GADfBSBR_1010(ex));
            }

            #endregion

            #region Retrieving customer details.

            ORM_CMN_BPT_CTM_Customer customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query {
                Ext_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID
            }).FirstOrDefault();
            if (customer == null)
            {
                Exception ex = new Exception("Retrieving ORM_CMN_BPT_CTM_Customer details failed.");
                return(new FR_L6BL_GADfBSBR_1010(ex));
            }

            #endregion

            #region Retriving method of payments (taking first one)

            ORM_BIL_BillHeader_MethodOfPayment methodOfPayment = ORM_BIL_BillHeader_MethodOfPayment.Query.Search(Connection, Transaction, new ORM_BIL_BillHeader_MethodOfPayment.Query
            {
                BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID
            }).FirstOrDefault();

            #endregion

            #region Retrieving payment type

            ORM_ACC_PAY_Type type = null;
            if (methodOfPayment != null)
            {
                type = ORM_ACC_PAY_Type.Query.Search(Connection, Transaction, new ORM_ACC_PAY_Type.Query {
                    ACC_PAY_TypeID = methodOfPayment.ACC_PAY_Type_RefID
                }).Single();
            }

            #endregion

            #region Retrieving payment condition

            ORM_ACC_PAY_Condition condition = ORM_ACC_PAY_Condition.Query.Search(Connection, Transaction, new ORM_ACC_PAY_Condition.Query {
                ACC_PAY_ConditionID = billHeader.BillHeader_PaymentCondition_RefID
            }).FirstOrDefault();

            #endregion


            #region Retrieving bill positions

            var allBillPositions = cls_Get_AllPositions_with_Articles_for_BillHeader.Invoke(Connection, Transaction, new P_L5BL_GAPwAfBH_1118 {
                BillHeaderID = billHeader.BIL_BillHeaderID
            }, securityTicket).Result;


            #endregion


            returnValue.Result = new L6BL_GADfBSBR_1010();
            returnValue.Result.BillShipmentBasedReportHeaderDetails = new L6BL_GADfBSBR_1010a();

            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderComment = billHeader.BillComment;
            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderDate    = billHeader.DateOnBill;
            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderNumber  = billHeader.BillNumber;
            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderTotalValue_BeforeTax    = billHeader.TotalValue_BeforeTax;
            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderTotalValue_IncludingTax = billHeader.TotalValue_IncludingTax;

            if (condition != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderPaymentDeadline = billHeader.DateOnBill.AddDays(condition.MaximumPaymentTreshold_InDays);
            }
            if (type != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderPaymentType = type.PaymentType_Name;
            }
            if (businessParticipant != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantDisplayName = businessParticipant.DisplayName;
            }
            if (customer != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantNumber = customer.InternalCustomerNumber;
            }
            if (universalContactDetails != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantStreetName   = universalContactDetails.Street_Name;
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantStreetNumber = universalContactDetails.Street_Number;
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantCity         = universalContactDetails.Town;
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantZipCode      = universalContactDetails.ZIP;
            }


            #region bill positions

            returnValue.Result.BillPositions = null;
            List <L6BL_GADfBSBR_1010bp> unsortedBillPositionsTemp = new List <L6BL_GADfBSBR_1010bp>();

            if (allBillPositions.ShipmentBillPositions != null)
            {
                var unsortedBillPositions =
                    allBillPositions.ShipmentBillPositions.Where(x => x.BillPosition.CMN_BPT_CTM_OrganizationalUnitID == Guid.Empty).ToList();

                foreach (L5BL_GBPwAfBH_1848 unsortedBillPosition in unsortedBillPositions)
                {
                    L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp();
                    tempBillPosition.BIL_BillPositionID = unsortedBillPosition.BillPosition.BIL_BillPositionID;
                    tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)unsortedBillPosition.BillPosition.PositionPricePerUnitValue_BeforeTax;
                    tempBillPosition.BillPosition_ValuePerUnit_AfterTax  = (double)unsortedBillPosition.BillPosition.PositionPricePerUnitValue_IncludingTax;
                    tempBillPosition.ACC_TAX_TaxeID     = unsortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID;
                    tempBillPosition.TaxRate            = unsortedBillPosition.Article.Taxes.First().TaxRate;
                    tempBillPosition.TaxName_DictID     = unsortedBillPosition.Article.Taxes.First().TaxName_DictID;
                    tempBillPosition.HeaderID           = unsortedBillPosition.BillPosition.LOG_SHP_Shipment_HeaderID;
                    tempBillPosition.Header_Number      = unsortedBillPosition.BillPosition.ShipmentHeader_Number;
                    tempBillPosition.Creation_Timestamp = unsortedBillPosition.BillPosition.LOG_SHP_ShipmentHeader_Creation_Timestamp;
                    tempBillPosition.IsShipmentPosition = true;
                    tempBillPosition.Quantity           = unsortedBillPosition.BillPosition.Quantity;
                    unsortedBillPositionsTemp.Add(tempBillPosition);
                }
            }
            // now for customer orders return
            if (allBillPositions.OrderReturnBillPosition != null)
            {
                var unsortedCustomerOrderReturnPositions =
                    allBillPositions.OrderReturnBillPosition.Where(x => x.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID == Guid.Empty).OrderBy(x => x.OrderReturnBillPosition.DateOfCustomerReturn).ToList();

                foreach (L5OR_GCORPwAfBH_1051 unsortedBillPosition in unsortedCustomerOrderReturnPositions)
                {
                    L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp();
                    tempBillPosition.BIL_BillPositionID = unsortedBillPosition.OrderReturnBillPosition.BIL_BillPositionID;
                    tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)unsortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_BeforeTax;
                    tempBillPosition.BillPosition_ValuePerUnit_AfterTax  = (double)unsortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_IncludingTax;
                    tempBillPosition.ACC_TAX_TaxeID     = unsortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID;
                    tempBillPosition.TaxRate            = unsortedBillPosition.Article.Taxes.First().TaxRate;
                    tempBillPosition.TaxName_DictID     = unsortedBillPosition.Article.Taxes.First().TaxName_DictID;
                    tempBillPosition.HeaderID           = unsortedBillPosition.OrderReturnBillPosition.ORD_CUO_CustomerOrderReturn_HeaderID;
                    tempBillPosition.Header_Number      = unsortedBillPosition.OrderReturnBillPosition.CustomerOrderReturnNumber;
                    tempBillPosition.Creation_Timestamp = unsortedBillPosition.OrderReturnBillPosition.Creation_Timestamp;
                    tempBillPosition.IsShipmentPosition = false;
                    tempBillPosition.Quantity           = unsortedBillPosition.OrderReturnBillPosition.Quantity;
                    unsortedBillPositionsTemp.Add(tempBillPosition);
                }
            }

            returnValue.Result.BillPositions = unsortedBillPositionsTemp.ToArray();


            #region bill position organisation unit

            returnValue.Result.OrganizationalUnits = null;
            List <L6BL_GADfBSBR_1010bo> organizationalUnitsTemp = new List <L6BL_GADfBSBR_1010bo>();

            if (allBillPositions.ShipmentBillPositions != null)
            {
                List <L5BL_GBPwAfBH_1848> sortedBillPositions = allBillPositions.ShipmentBillPositions.Where(x => x.BillPosition.CMN_BPT_CTM_OrganizationalUnitID != Guid.Empty).ToList();

                foreach (L5BL_GBPwAfBH_1848 sortedBillPosition in sortedBillPositions)
                {
                    L6BL_GADfBSBR_1010bo tempOrganizationalUnit = organizationalUnitsTemp.FirstOrDefault(organizationalUnitTemp => organizationalUnitTemp.CMN_BPT_CTM_OrganizationalUnitID == sortedBillPosition.BillPosition.CMN_BPT_CTM_OrganizationalUnitID);


                    if (tempOrganizationalUnit == null)
                    {
                        tempOrganizationalUnit = new L6BL_GADfBSBR_1010bo();
                        tempOrganizationalUnit.BillPositions = new L6BL_GADfBSBR_1010bp[0];

                        tempOrganizationalUnit.CMN_BPT_CTM_OrganizationalUnitID     = sortedBillPosition.BillPosition.CMN_BPT_CTM_OrganizationalUnitID;
                        tempOrganizationalUnit.OrganizationalUnit_SimpleName        = sortedBillPosition.BillPosition.OrganizationalUnit_SimpleName;
                        tempOrganizationalUnit.OrganizationalUnit_Name              = sortedBillPosition.BillPosition.OrganizationalUnit_Name_DictID;
                        tempOrganizationalUnit.OrganizationalUnit_Description       = sortedBillPosition.BillPosition.OrganizationalUnit_Name_DictID;
                        tempOrganizationalUnit.InternalOrganizationalUnitNumber     = sortedBillPosition.BillPosition.InternalOrganizationalUnitNumber;
                        tempOrganizationalUnit.InternalOrganizationalUnitSimpleName = sortedBillPosition.BillPosition.InternalOrganizationalUnitSimpleName;
                        tempOrganizationalUnit.ExternalOrganizationalUnitNumber     = sortedBillPosition.BillPosition.ExternalOrganizationalUnitNumber;

                        organizationalUnitsTemp.Add(tempOrganizationalUnit);
                    }

                    L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp();
                    tempBillPosition.BIL_BillPositionID = sortedBillPosition.BillPosition.BIL_BillPositionID;
                    tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)sortedBillPosition.BillPosition.PositionPricePerUnitValue_BeforeTax;
                    tempBillPosition.BillPosition_ValuePerUnit_AfterTax  = (double)sortedBillPosition.BillPosition.PositionPricePerUnitValue_IncludingTax;
                    tempBillPosition.ACC_TAX_TaxeID     = sortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID;
                    tempBillPosition.TaxRate            = sortedBillPosition.Article.Taxes.First().TaxRate;
                    tempBillPosition.TaxName_DictID     = sortedBillPosition.Article.Taxes.First().TaxName_DictID;
                    tempBillPosition.HeaderID           = sortedBillPosition.BillPosition.LOG_SHP_Shipment_HeaderID;
                    tempBillPosition.Header_Number      = sortedBillPosition.BillPosition.ShipmentHeader_Number;
                    tempBillPosition.Creation_Timestamp = sortedBillPosition.BillPosition.LOG_SHP_ShipmentHeader_Creation_Timestamp;
                    tempBillPosition.IsShipmentPosition = true;
                    tempBillPosition.Quantity           = sortedBillPosition.BillPosition.Quantity;
                    //hate this

                    List <L6BL_GADfBSBR_1010bp> currentBillPositions = tempOrganizationalUnit.BillPositions.ToList();
                    currentBillPositions.Add(tempBillPosition);
                    tempOrganizationalUnit.BillPositions = currentBillPositions.ToArray();
                }
            }

            // now for organization unit in customer order return

            if (allBillPositions.OrderReturnBillPosition != null)
            {
                List <L5OR_GCORPwAfBH_1051> sortedBillPositionsforCustomerOrderReturn = allBillPositions.OrderReturnBillPosition.Where(x => x.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID != Guid.Empty).OrderBy(x => x.OrderReturnBillPosition.DateOfCustomerReturn).ToList();

                foreach (L5OR_GCORPwAfBH_1051 sortedBillPosition in sortedBillPositionsforCustomerOrderReturn)
                {
                    L6BL_GADfBSBR_1010bo tempOrganizationalUnit = organizationalUnitsTemp.FirstOrDefault(organizationalUnitTemp => organizationalUnitTemp.CMN_BPT_CTM_OrganizationalUnitID == sortedBillPosition.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID);


                    if (tempOrganizationalUnit == null)
                    {
                        tempOrganizationalUnit = new L6BL_GADfBSBR_1010bo();
                        tempOrganizationalUnit.BillPositions = new L6BL_GADfBSBR_1010bp[0];

                        tempOrganizationalUnit.CMN_BPT_CTM_OrganizationalUnitID     = sortedBillPosition.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID;
                        tempOrganizationalUnit.OrganizationalUnit_SimpleName        = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_SimpleName;
                        tempOrganizationalUnit.OrganizationalUnit_Name              = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_Name_DictID;
                        tempOrganizationalUnit.OrganizationalUnit_Description       = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_Name_DictID;
                        tempOrganizationalUnit.InternalOrganizationalUnitNumber     = sortedBillPosition.OrderReturnBillPosition.InternalOrganizationalUnitNumber;
                        tempOrganizationalUnit.InternalOrganizationalUnitSimpleName = sortedBillPosition.OrderReturnBillPosition.InternalOrganizationalUnitSimpleName;
                        tempOrganizationalUnit.ExternalOrganizationalUnitNumber     = sortedBillPosition.OrderReturnBillPosition.ExternalOrganizationalUnitNumber;

                        organizationalUnitsTemp.Add(tempOrganizationalUnit);
                    }

                    L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp();
                    tempBillPosition.BIL_BillPositionID = sortedBillPosition.OrderReturnBillPosition.BIL_BillPositionID;
                    tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)sortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_BeforeTax;
                    tempBillPosition.BillPosition_ValuePerUnit_AfterTax  = (double)sortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_IncludingTax;
                    tempBillPosition.ACC_TAX_TaxeID     = sortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID;
                    tempBillPosition.TaxRate            = sortedBillPosition.Article.Taxes.First().TaxRate;
                    tempBillPosition.TaxName_DictID     = sortedBillPosition.Article.Taxes.First().TaxName_DictID;
                    tempBillPosition.HeaderID           = sortedBillPosition.OrderReturnBillPosition.ORD_CUO_CustomerOrderReturn_HeaderID;
                    tempBillPosition.Header_Number      = sortedBillPosition.OrderReturnBillPosition.CustomerOrderReturnNumber;
                    tempBillPosition.Creation_Timestamp = sortedBillPosition.OrderReturnBillPosition.Creation_Timestamp;
                    tempBillPosition.IsShipmentPosition = false;
                    tempBillPosition.Quantity           = sortedBillPosition.OrderReturnBillPosition.Quantity;
                    //hate this

                    List <L6BL_GADfBSBR_1010bp> currentBillPositions = tempOrganizationalUnit.BillPositions.ToList();
                    currentBillPositions.Add(tempBillPosition);
                    tempOrganizationalUnit.BillPositions = currentBillPositions.ToArray();
                }
            }

            returnValue.Result.OrganizationalUnits = organizationalUnitsTemp.ToArray();
            #endregion


            #endregion

            return(returnValue);

            #endregion UserCode
        }