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

            returnValue.Result = new L6TA_STTwDC_1146();

            Guid AppointmentTypeId = Guid.Empty;
            if (!Parameter.BaseData.IsDeleted)
            {
                AppointmentTypeId = cls_Save_TaskTemplate.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;

                if (Parameter.UpdateSlots)
                {
                    cls_Update_Slots_for_AppointmentTypeChange.Invoke(Connection, Transaction, new P_L5S_CSfATC_1242()
                    {
                        AppointmentTypeID = AppointmentTypeId
                    }, securityTicket);
                }
            }
            else
            {
                List <ORM_PPS_TSK_Task> existingAppointment = ORM_PPS_TSK_Task.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task.Query
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    InstantiatedFrom_TaskTemplate_RefID = Parameter.BaseData.PPS_TSK_Task_TemplateID
                }).ToList();

                if (existingAppointment.Count > 0) //cannot delete
                {
                    List <L6TA_STTwDC_1146_UsedInAppointment> usedAppointmentList = new List <L6TA_STTwDC_1146_UsedInAppointment>();

                    foreach (var appointment in existingAppointment)
                    {
                        usedAppointmentList.Add(new L6TA_STTwDC_1146_UsedInAppointment {
                            AppointmentName = appointment.DisplayName
                        });
                    }
                    returnValue.Result.UsedInAppointment = usedAppointmentList.ToArray();
                }

                List <ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability> existingOrgUnit = ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task_Template_OrganizationalUnitAvailability.Query
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    PPS_TSK_Task_Template_RefID = Parameter.BaseData.PPS_TSK_Task_TemplateID
                }).ToList();

                if (existingOrgUnit.Count > 0) //cannot delete
                {
                    List <L6TA_STTwDC_1146_UsedInOrgUnit> usedOrgUnitList = new List <L6TA_STTwDC_1146_UsedInOrgUnit>();

                    foreach (var orgUnit in existingOrgUnit)
                    {
                        ORM_CMN_STR_Office officeName = ORM_CMN_STR_Office.Query.Search(Connection, Transaction, new ORM_CMN_STR_Office.Query
                        {
                            IsDeleted        = false,
                            Tenant_RefID     = securityTicket.TenantID,
                            CMN_STR_OfficeID = orgUnit.CMN_STR_Office_RefID
                        }).Single();

                        usedOrgUnitList.Add(new L6TA_STTwDC_1146_UsedInOrgUnit {
                            OrgUnitName = officeName.Office_Name
                        });
                    }

                    returnValue.Result.UsedInOrgUnit = usedOrgUnitList.ToArray();
                }

                if (existingAppointment.Count == 0 && existingOrgUnit.Count == 0)
                {
                    AppointmentTypeId = cls_Save_TaskTemplate.Invoke(Connection, Transaction, Parameter.BaseData, securityTicket).Result;
                    if (Parameter.UpdateSlots)
                    {
                        cls_Delete_Slots_for_AppointmentTypeID.Invoke(Connection, Transaction, new P_L5BTS_DSfATID_1111()
                        {
                            AppointmentTypeID = Parameter.BaseData.PPS_TSK_Task_TemplateID
                        }, securityTicket);
                    }
                }
            }
            returnValue.Result.ID = AppointmentTypeId;

            return(returnValue);

            #endregion UserCode
        }
 ///<summary>
 /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured
 ///<summary>
 public static FR_L6TA_STTwDC_1146 Invoke(DbConnection Connection, DbTransaction Transaction, P_L6TA_STTwDC_1146 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L6TA_STTwDC_1146 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L6TA_STTwDC_1146 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L6TA_STTwDC_1146 functionReturn = new FR_L6TA_STTwDC_1146();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

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

                throw new Exception("Exception occured in method cls_Save_TaskTemplate_wihtDeleteCheck", ex);
            }
            return(functionReturn);
        }
 ///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_L6TA_STTwDC_1146 Invoke(string ConnectionString, P_L6TA_STTwDC_1146 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }