示例#1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2OF_SOA_1410 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.IsDefaultAddress)
            {
                //set previous flags as non default
                ORM_CMN_STR_Office_Address.Query.Update(Connection, Transaction,
                                                        new ORM_CMN_STR_Office_Address.Query()
                {
                    Office_RefID      = Parameter.OfficeID,
                    IsDefault         = true,
                    IsShippingAddress = Parameter.IsShippingAddress,
                    IsBillingAddress  = Parameter.IsBillingAddress
                },
                                                        new ORM_CMN_STR_Office_Address.Query()
                {
                    IsDefault = false
                }
                                                        );
            }

            var addressID = Guid.Empty;
            if (Parameter.AddressID == Guid.Empty)
            {
                //Create
                var saveAddressParam = new P_L2AD_SA_1755();
                saveAddressParam.CMN_AddressID   = Parameter.Address_Save.CMN_AddressID;
                saveAddressParam.CareOf          = Parameter.Address_Save.CareOf;
                saveAddressParam.Street_Name     = Parameter.Address_Save.Street_Name;
                saveAddressParam.Street_Number   = Parameter.Address_Save.Street_Number;
                saveAddressParam.City_PostalCode = Parameter.Address_Save.City_PostalCode;
                saveAddressParam.City_Name       = Parameter.Address_Save.City_Name;
                saveAddressParam.Country_Name    = Parameter.Address_Save.Country_Name;
                saveAddressParam.Country_ISOCode = Parameter.Address_Save.Country_ISOCode;
                addressID = cls_Save_Address.Invoke(Connection, Transaction, saveAddressParam, securityTicket).Result;

                var OfficeAddress = new ORM_CMN_STR_Office_Address();

                OfficeAddress.CMN_Address_RefID     = addressID;
                OfficeAddress.Office_RefID          = Parameter.OfficeID;
                OfficeAddress.IsBillingAddress      = Parameter.IsBillingAddress;
                OfficeAddress.IsShippingAddress     = Parameter.IsShippingAddress;
                OfficeAddress.IsSpecialAddress      = Parameter.IsSpecialAddress;
                OfficeAddress.IfSpecialAddress_Name = Parameter.IsSpecialAddress_Name;
                OfficeAddress.IsDefault             = Parameter.IsDefaultAddress;
                OfficeAddress.Tenant_RefID          = securityTicket.TenantID;
                OfficeAddress.Save(Connection, Transaction);
            }
            else
            {
                //Update
                addressID = Parameter.AddressID;

                var address = new ORM_CMN_Address();
                address.Load(Connection, Transaction, Parameter.AddressID);
                address.CareOf          = Parameter.Address_Save.CareOf;
                address.Street_Name     = Parameter.Address_Save.Street_Name;
                address.Street_Number   = Parameter.Address_Save.Street_Number;
                address.City_PostalCode = Parameter.Address_Save.City_PostalCode;
                address.City_Name       = Parameter.Address_Save.City_Name;
                address.Country_Name    = Parameter.Address_Save.Country_Name;
                address.Country_ISOCode = Parameter.Address_Save.Country_ISOCode;
                address.Save(Connection, Transaction);

                var queryOfficeAddress = new ORM_CMN_STR_Office_Address.Query();
                queryOfficeAddress.CMN_Address_RefID = Parameter.AddressID;
                queryOfficeAddress.Office_RefID      = Parameter.OfficeID;
                queryOfficeAddress.IsDeleted         = false;
                var officeAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, queryOfficeAddress).FirstOrDefault();

                officeAddress.IsDefault             = Parameter.IsDefaultAddress;
                officeAddress.IsBillingAddress      = Parameter.IsBillingAddress;
                officeAddress.IsShippingAddress     = Parameter.IsShippingAddress;
                officeAddress.IsSpecialAddress      = Parameter.IsSpecialAddress;
                officeAddress.IfSpecialAddress_Name = Parameter.IsSpecialAddress_Name;

                officeAddress.Save(Connection, Transaction);
            }


            #region Update DefaultAdresses

            var defaultShippingAddressQuery = new ORM_CMN_STR_Office_Address.Query();
            defaultShippingAddressQuery.Office_RefID      = Parameter.OfficeID;
            defaultShippingAddressQuery.IsDeleted         = false;
            defaultShippingAddressQuery.IsDefault         = true;
            defaultShippingAddressQuery.IsShippingAddress = true;
            var defaultShippingAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, defaultShippingAddressQuery).SingleOrDefault();

            var defaultBillingAddressQuery = new ORM_CMN_STR_Office_Address.Query();
            defaultBillingAddressQuery.Office_RefID     = Parameter.OfficeID;
            defaultBillingAddressQuery.IsDeleted        = false;
            defaultBillingAddressQuery.IsDefault        = true;
            defaultBillingAddressQuery.IsBillingAddress = true;
            var defaultBillingAddress = ORM_CMN_STR_Office_Address.Query.Search(Connection, Transaction, defaultBillingAddressQuery).SingleOrDefault();

            var office = new ORM_CMN_STR_Office();
            office.Load(Connection, Transaction, Parameter.OfficeID);

            office.Default_BillingAddress_RefID  = (defaultBillingAddress != null) ? defaultBillingAddress.CMN_Address_RefID : Guid.Empty;
            office.Default_ShippingAddress_RefID = (defaultShippingAddress != null) ? defaultShippingAddress.CMN_Address_RefID : Guid.Empty;
            office.Save(Connection, Transaction);

            #endregion

            return(returnValue);

            #endregion UserCode
        }
示例#2
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
        }