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

            var officeQuery = new ORM_CMN_STR_Office.Query();
            officeQuery.CMN_STR_OfficeID = Parameter.OfficeID;
            officeQuery.Tenant_RefID     = securityTicket.TenantID;
            var foundOffice = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery).Single();

            if (foundOffice != null)
            {
                var assignmentQuery = new ORM_CMN_BPT_EMP_Employee_2_Office.Query();
                assignmentQuery.CMN_BPT_EMP_Employee_RefID = Parameter.EmployeeID;
                assignmentQuery.CMN_STR_Office_RefID       = foundOffice.CMN_STR_OfficeID;
                assignmentQuery.Tenant_RefID = securityTicket.TenantID;
                var foundAssignment = ORM_CMN_BPT_EMP_Employee_2_Office.Query.Search(Connection, Transaction, assignmentQuery).SingleOrDefault();

                if (foundAssignment == null)
                {
                    foundAssignment = new ORM_CMN_BPT_EMP_Employee_2_Office();
                }

                foundAssignment.CMN_STR_Office_RefID       = foundOffice.CMN_STR_OfficeID;
                foundAssignment.CMN_BPT_EMP_Employee_RefID = Parameter.EmployeeID;
                foundAssignment.Tenant_RefID = securityTicket.TenantID;
                foundAssignment.IsDeleted    = false;
                foundAssignment.Save(Connection, Transaction);
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #2
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OF_DOD_1520 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

            var queryOfficeToDelete = new ORM_CMN_STR_Office.Query();
            queryOfficeToDelete.CMN_STR_OfficeID = Parameter.OfficeID;
            queryOfficeToDelete.Tenant_RefID     = securityTicket.TenantID;
            queryOfficeToDelete.IsDeleted        = false;
            var OfficeToDelete = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, queryOfficeToDelete).SingleOrDefault();

            if (OfficeToDelete != null)
            {
                var param = new P_L2O_SO_1529();
                param.CMN_STR_OfficeID = Parameter.OfficeID;
                param.IsDeleted        = true;

                var queryOfficeAddresses = new ORM_CMN_STR_Office_Address.Query();
                queryOfficeAddresses.Office_RefID = Parameter.OfficeID;
                queryOfficeAddresses.Tenant_RefID = securityTicket.TenantID;
                queryOfficeAddresses.IsDeleted    = false;

                //Locate all office addresses using connection table
                var OfficeAddresses = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, queryOfficeAddresses);

                foreach (var officeAddress in OfficeAddresses)
                {
                    var deleteAddressParam = new P_L2AD_SA_1755();
                    deleteAddressParam.CMN_AddressID = officeAddress.CMN_Address_RefID;
                    deleteAddressParam.IsDeleted     = true;
                    cls_Save_Address.Invoke(Connection, Transaction, deleteAddressParam);
                }

                cls_Save_Office.Invoke(Connection, Transaction, param);
            }

            var queryChildrenOfficesToDelete = new ORM_CMN_STR_Office.Query();
            queryChildrenOfficesToDelete.Parent_RefID = Parameter.OfficeID;
            queryChildrenOfficesToDelete.Tenant_RefID = securityTicket.TenantID;
            queryChildrenOfficesToDelete.IsDeleted    = false;
            var ChildrenOfficesToDelete = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, queryChildrenOfficesToDelete);

            if (ChildrenOfficesToDelete.Count > 0)
            {
                foreach (var childrenOffice in ChildrenOfficesToDelete)
                {
                    var deleteChildrenOfficeParam = new P_L5OF_DOD_1520();
                    deleteChildrenOfficeParam.OfficeID = childrenOffice.CMN_STR_OfficeID;
                    cls_Delete_Office_Deep.Invoke(Connection, Transaction, deleteChildrenOfficeParam, securityTicket);
                }
            }


            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
        }
        protected static FR_L5CM_CSNU_1524 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CM_CSNU_1524 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CM_CSNU_1524();

            StructureBuilderUtil structureBuilderUtil = new StructureBuilderUtil();
            TreeNodeUtil         treeNodeUtil         = new TreeNodeUtil();

            structureBuilderUtil.company         = cls_Get_Company_Structure_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;;
            structureBuilderUtil.sessionToken    = securityTicket.SessionTicket;
            structureBuilderUtil.addEmployees    = false;
            structureBuilderUtil.sessionSettings = cls_Get_Settings_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
            structureBuilderUtil.startDate       = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.Min(x => x.CalculationTimeframe_StartDate).Date;
            structureBuilderUtil.endDate         = DateTime.Now;
            structureBuilderUtil.hidenNodeType   = CompanyStructureType.None;
            structureBuilderUtil.employees       = new L5EM_GEFT_0959[0];

            EmployeeUtils employeeUtil = new EmployeeUtils();
            structureBuilderUtil.employeeUtil = employeeUtil;
            returnValue.Result = new L5CM_CSNU_1524();
            List <Node> companyStructure = structureBuilderUtil.organizeData(DateTime.Now);

            Node node = treeNodeUtil.findNodeForID(companyStructure[0], Parameter.ParentRefID);
            if (node != null && node.Children.Count != 0)
            {
                if (node.Children[0].data is L5OF_GOFT_1157)
                {
                    var officeQuery = new ORM_CMN_STR_Office.Query();
                    officeQuery.Tenant_RefID     = securityTicket.TenantID;
                    officeQuery.IsDeleted        = false;
                    officeQuery.Office_ShortName = Parameter.ShortName;
                    var officeQueryRes = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery);

                    if (officeQueryRes.Count > 0)
                    {
                        if (officeQueryRes.Count > 0)
                        {
                            returnValue.Result.OfficeID        = officeQueryRes[0].CMN_STR_OfficeID;
                            returnValue.Result.OfficeShortName = officeQueryRes[0].Office_ShortName;
                        }
                    }
                }
                else if (node.Children[0].data is L5WA_GWAFT_1201)
                {
                    var workareaQuery = new ORM_CMN_STR_PPS_WorkArea.Query();
                    workareaQuery.Tenant_RefID = securityTicket.TenantID;
                    workareaQuery.IsDeleted    = false;
                    workareaQuery.ShortName    = Parameter.ShortName;
                    if (node.data is L5WA_GWAFT_1201)
                    {
                        workareaQuery.Parent_RefID = Parameter.ParentRefID;
                    }
                    else
                    {
                        workareaQuery.Office_RefID = Parameter.ParentRefID;
                    }

                    var workareaQueryRes = ORM_CMN_STR_PPS_WorkArea.Query.Search(Connection, Transaction, workareaQuery);
                    if (workareaQueryRes.Count > 0)
                    {
                        returnValue.Result.WorkAreaID        = workareaQueryRes[0].CMN_STR_PPS_WorkAreaID;
                        returnValue.Result.WorkAreaShortName = workareaQueryRes[0].ShortName;
                    }
                }
                else if (node.Children[0].data is L5WP_GWFT_1203)
                {
                    var workplaceQuery = new ORM_CMN_STR_PPS_Workplace.Query();
                    workplaceQuery.Tenant_RefID   = securityTicket.TenantID;
                    workplaceQuery.IsDeleted      = false;
                    workplaceQuery.ShortName      = Parameter.ShortName;
                    workplaceQuery.WorkArea_RefID = Parameter.ParentRefID;
                    var workplaceQueryRes = ORM_CMN_STR_PPS_Workplace.Query.Search(Connection, Transaction, workplaceQuery);
                    if (workplaceQueryRes.Count > 0)
                    {
                        if (workplaceQueryRes.Count > 0)
                        {
                            returnValue.Result.WorkPlaceID        = workplaceQueryRes[0].CMN_STR_PPS_WorkplaceID;
                            returnValue.Result.WorkPlaceShortName = workplaceQueryRes[0].ShortName;
                        }
                    }
                }
            }


            return(returnValue);

            #endregion UserCode
        }
Пример #5
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PA_SPF_1413 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            var returnID    = Guid.Empty;

            if (Parameter.FindingID == Guid.Empty)
            {
                #region Save


                var officeQuery = new ORM_CMN_STR_Office.Query();
                officeQuery.CMN_STR_OfficeID  = Parameter.PracticeID;
                officeQuery.IsMedicalPractice = true;
                officeQuery.IsDeleted         = false;
                officeQuery.Tenant_RefID      = securityTicket.TenantID;

                var office = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery).SingleOrDefault();

                ORM_HEC_Patient_Finding patient_finding = new ORM_HEC_Patient_Finding();
                patient_finding.HEC_Patient_FindingID                = Guid.NewGuid();
                patient_finding.Patient_RefID                        = Parameter.PatientID;
                patient_finding.MedicalPractice_RefID                = office != null ? office.IfMedicalPractise_HEC_MedicalPractice_RefID : Guid.Empty;
                patient_finding.UndersigningDoctor_RefID             = Parameter.DoctorID;
                patient_finding.IfFindingFromReferral_Referral_RefID = Guid.NewGuid();
                patient_finding.Tenant_RefID           = securityTicket.TenantID;
                patient_finding.Creation_Timestamp     = Parameter.Date;
                patient_finding.Modification_Timestamp = DateTime.Now;
                patient_finding.Save(Connection, Transaction);

                ORM_HEC_ACT_PerformedAction_Referral referal = new ORM_HEC_ACT_PerformedAction_Referral();
                referal.HEC_ACT_PerformedAction_ReferralID = patient_finding.IfFindingFromReferral_Referral_RefID;
                referal.Tenant_RefID = securityTicket.TenantID;
                referal.ReferralTo_MedicalPractice_RefID = Parameter.ReferalPracticeID;
                referal.Creation_Timestamp     = DateTime.Now;
                referal.Modification_Timestamp = DateTime.Now;
                referal.ReferralTo_MedicalPracticeType_RefID = Parameter.ReferalTypeID;
                referal.Save(Connection, Transaction);

                returnID = patient_finding.HEC_Patient_FindingID;
                #endregion
            }
            else
            {
                if (Parameter.isDeleted)
                {
                    #region Delete
                    var patient_findingQuery = new ORM_HEC_Patient_Finding.Query();
                    patient_findingQuery.HEC_Patient_FindingID = Parameter.FindingID;
                    patient_findingQuery.Patient_RefID         = Parameter.PatientID;
                    patient_findingQuery.IsDeleted             = false;
                    patient_findingQuery.Tenant_RefID          = securityTicket.TenantID;

                    var patient_finding = ORM_HEC_Patient_Finding.Query.Search(Connection, Transaction, patient_findingQuery).Single();
                    patient_finding.IsDeleted = true;
                    patient_finding.Modification_Timestamp = DateTime.Now;
                    patient_finding.Save(Connection, Transaction);

                    var referalQuery = new ORM_HEC_ACT_PerformedAction_Referral.Query();
                    referalQuery.HEC_ACT_PerformedAction_ReferralID = patient_finding.IfFindingFromReferral_Referral_RefID;
                    referalQuery.IsDeleted    = false;
                    referalQuery.Tenant_RefID = securityTicket.TenantID;

                    var referal = ORM_HEC_ACT_PerformedAction_Referral.Query.Search(Connection, Transaction, referalQuery).Single();
                    referal.IsDeleted = true;
                    referal.Modification_Timestamp = DateTime.Now;
                    referal.Save(Connection, Transaction);
                    #endregion
                }
                else
                {
                    #region Edit
                    var officeQuery = new ORM_CMN_STR_Office.Query();
                    officeQuery.CMN_STR_OfficeID  = Parameter.PracticeID;
                    officeQuery.IsMedicalPractice = true;
                    officeQuery.IsDeleted         = false;
                    officeQuery.Tenant_RefID      = securityTicket.TenantID;

                    var office = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery).SingleOrDefault();

                    var patient_findingQuery = new ORM_HEC_Patient_Finding.Query();
                    patient_findingQuery.HEC_Patient_FindingID = Parameter.FindingID;
                    patient_findingQuery.Patient_RefID         = Parameter.PatientID;
                    patient_findingQuery.IsDeleted             = false;
                    patient_findingQuery.Tenant_RefID          = securityTicket.TenantID;

                    var patient_finding = ORM_HEC_Patient_Finding.Query.Search(Connection, Transaction, patient_findingQuery).Single();
                    patient_finding.Patient_RefID            = Parameter.PatientID;
                    patient_finding.MedicalPractice_RefID    = office != null ? office.IfMedicalPractise_HEC_MedicalPractice_RefID : Guid.Empty;
                    patient_finding.UndersigningDoctor_RefID = Parameter.DoctorID;
                    patient_finding.Modification_Timestamp   = DateTime.Now;
                    patient_finding.Save(Connection, Transaction);

                    var referalQuery = new ORM_HEC_ACT_PerformedAction_Referral.Query();
                    referalQuery.HEC_ACT_PerformedAction_ReferralID = patient_finding.IfFindingFromReferral_Referral_RefID;
                    referalQuery.IsDeleted    = false;
                    referalQuery.Tenant_RefID = securityTicket.TenantID;

                    var referal = ORM_HEC_ACT_PerformedAction_Referral.Query.Search(Connection, Transaction, referalQuery).Single();
                    referal.Modification_Timestamp = DateTime.Now;
                    referal.ReferralTo_MedicalPracticeType_RefID = Parameter.ReferalTypeID;
                    referal.ReferralTo_MedicalPractice_RefID     = Parameter.ReferalPracticeID;
                    referal.Save(Connection, Transaction);

                    returnID = patient_finding.HEC_Patient_FindingID;
                    #endregion
                }
            }

            returnValue.Result = returnID;
            return(returnValue);

            #endregion UserCode
        }
Пример #6
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OU_SOUGD_1221 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            #region Save
            if (Parameter.OrgUnitID == null || Parameter.OrgUnitID == Guid.Empty)
            {
                //*******************MedicalPracticeType************************

                var medicalPractice = new ORM_HEC_MedicalPractis();
                medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                medicalPractice.IsDeleted             = false;
                medicalPractice.Save(Connection, Transaction);

                foreach (var item in Parameter.MedicalPracticeType)
                {
                    var medicalPractice2PracticeType = new ORM_HEC_MedicalPractice_2_PracticeType();
                    medicalPractice2PracticeType.AssignmentID = Guid.NewGuid();
                    medicalPractice2PracticeType.HEC_MedicalPractice_Type_RefID = item.HEC_MedicalPractice_TypeID;
                    medicalPractice2PracticeType.HEC_MedicalPractice_RefID      = medicalPractice.HEC_MedicalPractiseID;
                    medicalPractice2PracticeType.Tenant_RefID = securityTicket.TenantID;
                    medicalPractice2PracticeType.IsDeleted    = false;
                    medicalPractice2PracticeType.Save(Connection, Transaction);
                }

                //******************* Office************************
                var Office = new ORM_CMN_STR_Office();
                Office.CMN_STR_OfficeID = Guid.NewGuid();
                Office.Office_Name      = Parameter.OrgUnitName_DictID;
                Office.Tenant_RefID     = securityTicket.TenantID;
                if (Parameter.ParentID != null && Parameter.ParentID != Guid.Empty)
                {
                    Office.Parent_RefID = Parameter.ParentID;
                }
                Office.Creation_Timestamp = DateTime.Now;

                var officeQuery = new ORM_CMN_STR_Office.Query();
                officeQuery.Tenant_RefID = securityTicket.TenantID;
                int officeCount = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery).Count;

                Office.Office_InternalNumber       = String.Format("{0:00000}", officeCount + 1);
                Office.Default_PhoneNumber         = Parameter.Telephone;
                Office.DisplayImage_Document_RefID = Parameter.DisplayImage_Document_RefID;
                Office.Default_Email      = Parameter.Email;
                Office.Default_Website    = Parameter.Website;
                Office.Office_Description = new Dict("cmn_str_offices");
                Office.Comment            = Parameter.Notes;
                Office.IsMedicalPractice  = true;
                Office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                Office.Save(Connection, Transaction);

                //*******************Save Address************************

                foreach (var address in Parameter.Adresses)
                {
                    var Office_2_Address = new ORM_CMN_STR_Office_Address();
                    Office_2_Address.CMN_STR_Office_AddressID = Guid.NewGuid();
                    Office_2_Address.IsBillingAddress         = address.IsBillingAddress;
                    Office_2_Address.IsShippingAddress        = address.IsShippingAddress;
                    Office_2_Address.IsSpecialAddress         = address.IsSpecialAddress;
                    Office_2_Address.CMN_Address_RefID        = address.AddressID;
                    Office_2_Address.Office_RefID             = Office.CMN_STR_OfficeID;
                    Office_2_Address.Tenant_RefID             = securityTicket.TenantID;
                    Office_2_Address.Creation_Timestamp       = DateTime.Now;
                    Office_2_Address.IsDefault = address.IsDefault;
                    Office_2_Address.Save(Connection, Transaction);

                    var Address = new ORM_CMN_Address();
                    Address.CMN_AddressID      = Office_2_Address.CMN_Address_RefID;
                    Address.Tenant_RefID       = securityTicket.TenantID;
                    Address.Creation_Timestamp = DateTime.Now;
                    Address.City_Name          = address.City;
                    Address.Street_Name        = address.Street_Name;
                    Address.Street_Number      = address.Street_Number;
                    Address.Country_ISOCode    = address.CountryISO;
                    Address.Country_Name       = address.CountryName;
                    Address.City_PostalCode    = address.ZIP;
                    if (address.IsDefault)
                    {
                        Address.Lattitude = address.Lattitude;
                        Address.Longitude = address.Longitude;
                    }
                    Address.Save(Connection, Transaction);
                }

                //*******************Save Languages************************

                foreach (var item in Parameter.SpokenLanguage)
                {
                    var officeSpokenLanguages = new ORM_CMN_STR_Office_SpokenLanguage();
                    officeSpokenLanguages.CMN_STR_Office_SpokenLanguageID = Guid.NewGuid();
                    officeSpokenLanguages.Office_RefID   = Office.CMN_STR_OfficeID;
                    officeSpokenLanguages.Language_RefID = item.CMN_LanguageID;
                    officeSpokenLanguages.IsDeleted      = item.IsDeleted;
                    officeSpokenLanguages.Tenant_RefID   = securityTicket.TenantID;
                    officeSpokenLanguages.Save(Connection, Transaction);
                }

                //*******************Save Contact Person************************

                var responsiblePerson = new ORM_CMN_STR_Office_ResponsiblePerson();
                responsiblePerson.CMN_STR_Office_ResponsiblePersonID = Guid.NewGuid();
                responsiblePerson.Office_RefID = Office.CMN_STR_OfficeID;
                responsiblePerson.CMN_BPT_EMP_Employee_RefID = Guid.NewGuid();
                responsiblePerson.Tenant_RefID       = securityTicket.TenantID;
                responsiblePerson.Creation_Timestamp = DateTime.Now;
                responsiblePerson.Save(Connection, Transaction);

                var employee = new ORM_CMN_BPT_EMP_Employee();
                employee.CMN_BPT_EMP_EmployeeID    = responsiblePerson.CMN_BPT_EMP_Employee_RefID;
                employee.BusinessParticipant_RefID = Guid.NewGuid();
                employee.Creation_Timestamp        = DateTime.Now;
                employee.Tenant_RefID = securityTicket.TenantID;
                employee.Save(Connection, Transaction);

                var businessParticpant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticpant.CMN_BPT_BusinessParticipantID = employee.BusinessParticipant_RefID;
                businessParticpant.IsNaturalPerson    = true;
                businessParticpant.DisplayName        = Parameter.ContactPerson.Title + " " + Parameter.ContactPerson.FirstName + " " + Parameter.ContactPerson.LastName;
                businessParticpant.Tenant_RefID       = securityTicket.TenantID;
                businessParticpant.Creation_Timestamp = DateTime.Now;
                businessParticpant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                businessParticpant.Save(Connection, Transaction);

                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = businessParticpant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Title              = Parameter.ContactPerson.Title;
                personInfo.FirstName          = Parameter.ContactPerson.FirstName;
                personInfo.LastName           = Parameter.ContactPerson.LastName;
                personInfo.Tenant_RefID       = securityTicket.TenantID;
                personInfo.Creation_Timestamp = DateTime.Now;
                personInfo.Save(Connection, Transaction);

                //*******************AppointmentType************************

                foreach (var item in Parameter.AppoitmentType)
                {
                    ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability orgUnitToAppointmentType = new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability();
                    orgUnitToAppointmentType.PPS_TSK_Task_Template_OrganizationalUnitAvailabilityID = Guid.NewGuid();
                    orgUnitToAppointmentType.CMN_STR_Office_RefID        = Office.CMN_STR_OfficeID;
                    orgUnitToAppointmentType.PPS_TSK_Task_Template_RefID = item.PPS_TSK_Task_Template_RefID;
                    orgUnitToAppointmentType.Creation_Timestamp          = DateTime.Now;
                    orgUnitToAppointmentType.Tenant_RefID = securityTicket.TenantID;
                    orgUnitToAppointmentType.Save(Connection, Transaction);
                }

                returnValue.Result = Office.CMN_STR_OfficeID;
            }
            #endregion
            #region Delete
            else if (Parameter.IsDeleted)
            {
                List <Guid> guidList = new List <Guid>();
                guidList.Add(Parameter.OrgUnitID);
                cls_Delete_OrgsUnitsGeneralData.Invoke(Connection, Transaction, new P_L5OU_DOUGD_1221 {
                    OrgUnitID = guidList.ToArray()
                }, securityTicket);
            }
            #endregion
            #region Edit
            else
            {
                var officeQuery = new ORM_CMN_STR_Office.Query()
                {
                    Tenant_RefID     = securityTicket.TenantID,
                    IsDeleted        = false,
                    CMN_STR_OfficeID = Parameter.OrgUnitID
                };

                var office = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery).Single();
                office.Office_Name                 = Parameter.OrgUnitName_DictID;
                office.Default_PhoneNumber         = Parameter.Telephone;
                office.DisplayImage_Document_RefID = Parameter.DisplayImage_Document_RefID;
                office.Default_Email               = Parameter.Email;
                office.Comment         = Parameter.Notes;
                office.Default_Website = Parameter.Website;
                if (Parameter.ParentID != null && Parameter.ParentID != Guid.Empty)
                {
                    office.Parent_RefID = Parameter.ParentID;
                }
                office.IsMedicalPractice = true;
                office.Save(Connection, Transaction);

                //*******************Medical practice type************************

                var medicalPractice2TypeQuery = new ORM_HEC_MedicalPractice_2_PracticeType.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID
                };
                var medicalPractice2Type = ORM_HEC_MedicalPractice_2_PracticeType.Query.Search(Connection, Transaction, medicalPractice2TypeQuery).ToList();

                foreach (var item in Parameter.MedicalPracticeType)
                {
                    if (item.IsDeleted)
                    {
                        foreach (var medicalPractice2TypeItem in medicalPractice2Type)
                        {
                            if (medicalPractice2TypeItem.HEC_MedicalPractice_Type_RefID == item.HEC_MedicalPractice_TypeID)
                            {
                                medicalPractice2TypeItem.Tenant_RefID = securityTicket.TenantID;
                                if (office.IfMedicalPractise_HEC_MedicalPractice_RefID != Guid.Empty)
                                {
                                    medicalPractice2TypeItem.HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID;
                                }
                                else
                                {
                                    var medicalPractice = new ORM_HEC_MedicalPractis();
                                    medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                                    medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                                    medicalPractice.IsDeleted             = false;
                                    medicalPractice.Save(Connection, Transaction);
                                    office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                    office.Save(Connection, Transaction);
                                    medicalPractice2TypeItem.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                }
                                medicalPractice2TypeItem.IsDeleted = true;
                                medicalPractice2TypeItem.Save(Connection, Transaction);
                                break;
                            }
                        }
                    }
                    else
                    {
                        ORM_HEC_MedicalPractice_2_PracticeType medPracticeType = null;
                        foreach (var medicalPractice2TypeItem in medicalPractice2Type)
                        {
                            if (medicalPractice2TypeItem.HEC_MedicalPractice_Type_RefID == item.HEC_MedicalPractice_TypeID)
                            {
                                medPracticeType = medicalPractice2TypeItem;
                                if (medPracticeType.HEC_MedicalPractice_RefID == Guid.Empty)
                                {
                                    var medicalPractice = new ORM_HEC_MedicalPractis();
                                    medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                                    medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                                    medicalPractice.IsDeleted             = false;
                                    medicalPractice.Save(Connection, Transaction);
                                    office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                    office.Save(Connection, Transaction);
                                    medPracticeType.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                    medPracticeType.Save(Connection, Transaction);
                                }
                                break;
                            }
                        }

                        if (medPracticeType == null)
                        {
                            medPracticeType = new ORM_HEC_MedicalPractice_2_PracticeType();
                            medPracticeType.Tenant_RefID = securityTicket.TenantID;
                            medPracticeType.IsDeleted    = false;
                            medPracticeType.HEC_MedicalPractice_Type_RefID = item.HEC_MedicalPractice_TypeID;
                            if (office.IfMedicalPractise_HEC_MedicalPractice_RefID != Guid.Empty)
                            {
                                medPracticeType.HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID;
                            }
                            else
                            {
                                var medicalPractice = new ORM_HEC_MedicalPractis();
                                medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                                medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                                medicalPractice.IsDeleted             = false;
                                medicalPractice.Save(Connection, Transaction);
                                office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                office.Save(Connection, Transaction);
                                medPracticeType.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                            }
                            medPracticeType.Save(Connection, Transaction);
                        }
                        else
                        {
                            if (medPracticeType.IsDeleted)
                            {
                                medPracticeType.Tenant_RefID = securityTicket.TenantID;
                                medPracticeType.IsDeleted    = true;
                                if (office.IfMedicalPractise_HEC_MedicalPractice_RefID != Guid.Empty)
                                {
                                    medPracticeType.HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID;
                                }
                                else
                                {
                                    var medicalPractice = new ORM_HEC_MedicalPractis();
                                    medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                                    medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                                    medicalPractice.IsDeleted             = false;
                                    medicalPractice.Save(Connection, Transaction);
                                    office.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                    office.Save(Connection, Transaction);
                                    medPracticeType.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                }
                                medPracticeType.Save(Connection, Transaction);
                            }
                        }
                    }
                }

                //*******************Save Spoken Languages************************

                var office_spoken_languages = new ORM_CMN_STR_Office_SpokenLanguage.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    Office_RefID = office.CMN_STR_OfficeID,
                    IsDeleted    = false
                };

                var officeSpokenLanguageQuery = ORM_CMN_STR_Office_SpokenLanguage.Query.Search(Connection, Transaction, office_spoken_languages);

                foreach (var item in Parameter.SpokenLanguage)
                {
                    ORM_CMN_STR_Office_SpokenLanguage officeSpokenLang = null;
                    foreach (var officeSpokenLanguageItem in officeSpokenLanguageQuery)
                    {
                        if (officeSpokenLanguageItem.Language_RefID == item.CMN_LanguageID && officeSpokenLanguageItem.Office_RefID == office.CMN_STR_OfficeID)
                        {
                            officeSpokenLang = officeSpokenLanguageItem;
                            break;
                        }
                    }
                    if (officeSpokenLang == null)
                    {
                        var officeSpokenLanguage = new ORM_CMN_STR_Office_SpokenLanguage();
                        officeSpokenLanguage.CMN_STR_Office_SpokenLanguageID = Guid.NewGuid();
                        officeSpokenLanguage.Language_RefID = item.CMN_LanguageID;
                        officeSpokenLanguage.IsDeleted      = item.IsDeleted;
                        officeSpokenLanguage.Office_RefID   = office.CMN_STR_OfficeID;
                        officeSpokenLanguage.Tenant_RefID   = securityTicket.TenantID;
                        officeSpokenLanguage.Save(Connection, Transaction);
                    }
                    else
                    {
                        officeSpokenLang.Language_RefID = item.CMN_LanguageID;
                        officeSpokenLang.IsDeleted      = item.IsDeleted;
                        officeSpokenLang.Save(Connection, Transaction);
                    }
                }


                //*******************Save Address************************

                foreach (var address in Parameter.Adresses)
                {
                    var Office_2_Address = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, new ORM_CMN_STR_Office_Address.Query()
                    {
                        IsBillingAddress  = address.IsBillingAddress,
                        IsShippingAddress = address.IsShippingAddress,
                        IsSpecialAddress  = address.IsSpecialAddress,
                        Office_RefID      = office.CMN_STR_OfficeID,
                        Tenant_RefID      = securityTicket.TenantID,
                        CMN_Address_RefID = address.AddressID,
                        IsDeleted         = false
                    }).SingleOrDefault();

                    if (Office_2_Address == null)
                    {
                        Office_2_Address = new ORM_CMN_STR_Office_Address();
                        Office_2_Address.CMN_STR_Office_AddressID = Guid.NewGuid();
                        Office_2_Address.IsBillingAddress         = address.IsBillingAddress;
                        Office_2_Address.IsShippingAddress        = address.IsShippingAddress;
                        Office_2_Address.IsSpecialAddress         = address.IsSpecialAddress;
                        Office_2_Address.CMN_Address_RefID        = address.AddressID;
                        Office_2_Address.Office_RefID             = office.CMN_STR_OfficeID;
                        Office_2_Address.Tenant_RefID             = securityTicket.TenantID;
                        Office_2_Address.Creation_Timestamp       = DateTime.Now;
                    }

                    Office_2_Address.IsDefault = address.IsDefault;

                    var Address = ORM_CMN_Address.Query.Search(Connection, Transaction, new ORM_CMN_Address.Query()
                    {
                        Tenant_RefID  = securityTicket.TenantID,
                        IsDeleted     = false,
                        CMN_AddressID = Office_2_Address.CMN_Address_RefID
                    }).SingleOrDefault();

                    if (Address == null)
                    {
                        Address = new ORM_CMN_Address();
                        Address.CMN_AddressID      = Office_2_Address.CMN_Address_RefID;
                        Address.Tenant_RefID       = securityTicket.TenantID;
                        Address.Creation_Timestamp = DateTime.Now;
                    }

                    if (address.IsDeleted)
                    {
                        Address.IsDeleted          = true;
                        Office_2_Address.IsDeleted = true;
                    }
                    else
                    {
                        Address.City_Name       = address.City;
                        Address.Street_Name     = address.Street_Name;
                        Address.Street_Number   = address.Street_Number;
                        Address.Country_ISOCode = address.CountryISO;
                        Address.Country_Name    = address.CountryName;
                        Address.City_PostalCode = address.ZIP;
                        if (address.IsDefault)
                        {
                            Address.Lattitude = address.Lattitude;
                            Address.Longitude = address.Longitude;
                        }
                    }
                    Office_2_Address.Save(Connection, Transaction);
                    Address.Save(Connection, Transaction);
                }


                //*******************AppointmentType************************

                foreach (var item in Parameter.AppoitmentType)
                {
                    var orgUnitToAppointmentTypeQuery = new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query();
                    orgUnitToAppointmentTypeQuery.CMN_STR_Office_RefID        = Parameter.OrgUnitID;
                    orgUnitToAppointmentTypeQuery.PPS_TSK_Task_Template_RefID = item.PPS_TSK_Task_Template_RefID;
                    orgUnitToAppointmentTypeQuery.Tenant_RefID = securityTicket.TenantID;
                    orgUnitToAppointmentTypeQuery.IsDeleted    = false;

                    var orgUnitToAppointmentType = ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query.Search(Connection, Transaction, orgUnitToAppointmentTypeQuery).SingleOrDefault();

                    if (orgUnitToAppointmentType == null)
                    {
                        if (!item.IsDeleted)
                        {
                            orgUnitToAppointmentType = new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability();
                            orgUnitToAppointmentType.PPS_TSK_Task_Template_OrganizationalUnitAvailabilityID = Guid.NewGuid();
                            orgUnitToAppointmentType.CMN_STR_Office_RefID        = Parameter.OrgUnitID;
                            orgUnitToAppointmentType.PPS_TSK_Task_Template_RefID = item.PPS_TSK_Task_Template_RefID;
                            orgUnitToAppointmentType.Creation_Timestamp          = DateTime.Now;
                            orgUnitToAppointmentType.Tenant_RefID = securityTicket.TenantID;
                            orgUnitToAppointmentType.Save(Connection, Transaction);
                        }
                    }
                    else
                    {
                        if (item.IsDeleted)
                        {
                            orgUnitToAppointmentType.IsDeleted = true;
                            orgUnitToAppointmentType.Save(Connection, Transaction);
                        }
                    }
                }


                //*******************Save Contact Person************************

                var responsiblePerson = ORM_CMN_STR_Office_ResponsiblePerson.Query.Search(Connection, Transaction, new ORM_CMN_STR_Office_ResponsiblePerson.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    Office_RefID = office.CMN_STR_OfficeID
                }).Single();

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                {
                    Tenant_RefID           = securityTicket.TenantID,
                    IsDeleted              = false,
                    CMN_BPT_EMP_EmployeeID = responsiblePerson.CMN_BPT_EMP_Employee_RefID
                }).Single();

                var businessParticpant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    CMN_BPT_BusinessParticipantID = employee.BusinessParticipant_RefID
                }).Single();
                businessParticpant.DisplayName = Parameter.ContactPerson.Title + " " + Parameter.ContactPerson.FirstName + " " + Parameter.ContactPerson.LastName;
                businessParticpant.Save(Connection, Transaction);

                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 = businessParticpant.IfNaturalPerson_CMN_PER_PersonInfo_RefID
                }).Single();
                personInfo.Title     = Parameter.ContactPerson.Title;
                personInfo.FirstName = Parameter.ContactPerson.FirstName;
                personInfo.LastName  = Parameter.ContactPerson.LastName;
                personInfo.Save(Connection, Transaction);

                returnValue.Result = office.CMN_STR_OfficeID;
            }
            #endregion

            return(returnValue);

            #endregion UserCode
        }
Пример #7
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OU_DOUGD_1221 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            foreach (var OrgUnitID in Parameter.OrgUnitID)
            {
                //delete  office
                var officeQuery = new ORM_CMN_STR_Office.Query();
                officeQuery.Tenant_RefID     = securityTicket.TenantID;
                officeQuery.IsDeleted        = false;
                officeQuery.CMN_STR_OfficeID = OrgUnitID;

                var office = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQuery).Single();
                //delete Medical practice type
                ORM_HEC_MedicalPractice_2_PracticeType.Query.SoftDelete(Connection, Transaction, new ORM_HEC_MedicalPractice_2_PracticeType.Query
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    HEC_MedicalPractice_RefID = office.IfMedicalPractise_HEC_MedicalPractice_RefID
                });
                office.IsDeleted = true;
                office.Save(Connection, Transaction);

                //delete Addresses

                var addressQuery = new ORM_CMN_STR_Office_Address.Query();
                addressQuery.IsDeleted    = false;
                addressQuery.Tenant_RefID = securityTicket.TenantID;
                addressQuery.Office_RefID = OrgUnitID;

                var addressList = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, addressQuery).ToList();

                foreach (var address in addressList)
                {
                    address.IsDeleted = true;
                    address.Save(Connection, Transaction);

                    var addressDataQuery = new ORM_CMN_Address.Query();
                    addressDataQuery.IsDeleted     = false;
                    addressDataQuery.CMN_AddressID = address.CMN_Address_RefID;

                    var addressData = ORM_CMN_Address.Query.Search(Connection, Transaction, addressDataQuery).Single();
                    addressData.IsDeleted = true;
                    addressData.Save(Connection, Transaction);
                }

                //delete Unit Speciality

                //var office_2_officeTypeQuery = new ORM_CMN_STR_Office_2_OfficeType.Query();
                //office_2_officeTypeQuery.IsDeleted = false;
                //office_2_officeTypeQuery.Office_RefID = OrgUnitID;

                //var office_2_officeType = ORM_CMN_STR_Office_2_OfficeType.Query.Search(Connection, Transaction, office_2_officeTypeQuery).First();
                //office_2_officeType.IsDeleted = true;
                //office_2_officeType.Save(Connection, Transaction);

                //delete contact person data
                var responsiblePersonQuery = new ORM_CMN_STR_Office_ResponsiblePerson.Query();
                responsiblePersonQuery.Office_RefID = OrgUnitID;
                responsiblePersonQuery.IsDeleted    = false;

                var responsiblePerson = ORM_CMN_STR_Office_ResponsiblePerson.Query.Search(Connection, Transaction, responsiblePersonQuery).First();
                responsiblePerson.IsDeleted = true;
                responsiblePerson.Save(Connection, Transaction);

                var employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
                employeeQuery.IsDeleted = false;
                employeeQuery.CMN_BPT_EMP_EmployeeID = responsiblePerson.CMN_BPT_EMP_Employee_RefID;

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery).Single();
                employee.IsDeleted = true;
                employee.Save(Connection, Transaction);

                var businessParticpantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                businessParticpantQuery.CMN_BPT_BusinessParticipantID = employee.BusinessParticipant_RefID;
                businessParticpantQuery.IsDeleted = false;

                var businessParticpant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticpantQuery).Single();
                businessParticpant.IsDeleted = true;
                businessParticpant.Save(Connection, Transaction);

                var personInfoQuery = new ORM_CMN_PER_PersonInfo.Query();
                personInfoQuery.CMN_PER_PersonInfoID = businessParticpant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfoQuery.IsDeleted            = false;

                var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQuery).Single();
                personInfo.IsDeleted = true;
                personInfo.Save(Connection, Transaction);

                //delete all children
                var officeQueryChildren = new ORM_CMN_STR_Office.Query();
                officeQueryChildren.Tenant_RefID = securityTicket.TenantID;
                officeQueryChildren.IsDeleted    = false;
                officeQueryChildren.Parent_RefID = OrgUnitID;

                //delete connection to appointmetn types

                var orgUnitToAppointmentTypeQuery = new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query();
                orgUnitToAppointmentTypeQuery.CMN_STR_Office_RefID = OrgUnitID;
                orgUnitToAppointmentTypeQuery.Tenant_RefID         = securityTicket.TenantID;
                orgUnitToAppointmentTypeQuery.IsDeleted            = false;

                var orgUnitToAppointmentTypeList = ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query.Search(Connection, Transaction, orgUnitToAppointmentTypeQuery).ToList();

                foreach (var item in orgUnitToAppointmentTypeList)
                {
                    item.IsDeleted = true;
                    item.Save(Connection, Transaction);
                }

                var officeChildrenList = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, officeQueryChildren).ToList();

                if (officeChildrenList.Count > 0)
                {
                    List <Guid> guidList = new List <Guid>();
                    foreach (var officeChildren in officeChildrenList)
                    {
                        guidList.Add(officeChildren.CMN_STR_OfficeID);
                    }
                    cls_Delete_OrgsUnitsGeneralData.Invoke(Connection, Transaction, new P_L5OU_DOUGD_1221 {
                        OrgUnitID = guidList.ToArray()
                    }, securityTicket);
                }
            }
            return(returnValue);

            #endregion UserCode
        }