///<summary>
 /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured
 ///<summary>
 public static FR_L5CO_SCOHaP_1043 Invoke(DbConnection Connection, DbTransaction Transaction, P_L5CO_SCOHaP_1043 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }
        protected static FR_L5CO_SCOHaP_1043 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_SCOHaP_1043 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CO_SCOHaP_1043();
            returnValue.Result = new L5CO_SCOHaP_1043();

            var resultCustomerOrderHeader = cls_Save_CustomerOrderHeader.Invoke(Connection, Transaction, Parameter.Header, securityTicket).Result;
            returnValue.Result.CustomerOrderHeaderId  = resultCustomerOrderHeader.CustomerOrderHeaderId;
            returnValue.Result.CustomerInteractionsId = resultCustomerOrderHeader.CustomerInteractionsId;
            Parameter.Positions.CustomerOrderHeaderID = resultCustomerOrderHeader.CustomerOrderHeaderId;
            var positionsResults = cls_Save_CustomerOrderPositions.Invoke(Connection, Transaction, Parameter.Positions, securityTicket).Result;

            #region Update Customer Order Total Value
            var header = new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Header();
            header.Load(Connection, Transaction, resultCustomerOrderHeader.CustomerOrderHeaderId);

            var positions = CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Position.Query.Search(Connection, Transaction,
                                                                                        new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Position.Query
            {
                CustomerOrder_Header_RefID = resultCustomerOrderHeader.CustomerOrderHeaderId,
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            });
            header.TotalValue_BeforeTax = positions.Sum(x => x.Position_ValueTotal);
            header.Save(Connection, Transaction);
            #endregion

            P_L5CO_AOWS_1447 acceptParameter = new P_L5CO_AOWS_1447
            {
                CustomerOrderHeaderID = resultCustomerOrderHeader.CustomerOrderHeaderId,
                Message = String.Empty
            };

            cls_AcceptOrderWithShipment.Invoke(Connection, Transaction, acceptParameter, securityTicket);

            return(returnValue);

            #endregion UserCode
        }
 ///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_L5CO_SCOHaP_1043 Invoke(string ConnectionString, P_L5CO_SCOHaP_1043 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L5CO_SCOHaP_1043 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5CO_SCOHaP_1043 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L5CO_SCOHaP_1043 functionReturn = new FR_L5CO_SCOHaP_1043();

            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_CustomerOrder_Header_and_Positions", ex);
            }
            return(functionReturn);
        }