///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L5CO_COH_1326 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5CO_COH_1326 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L5CO_COH_1326 functionReturn = new FR_L5CO_COH_1326();

            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_CustomerOrderHeader", ex);
            }
            return(functionReturn);
        }
        protected static FR_L5CO_COH_1326 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_COH_1326 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CO_COH_1326();
            returnValue.Result = new L5CO_COH_1326();

            var header = new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Header();
            ORM_CMN_POS_CustomerInteraction customerInteraction = null;

            if (Parameter.CustomerOrderHeaderID == Guid.Empty)
            {
                #region Preload data

                var incrNumberParam = new P_L2NR_GaIINfUA_1454()
                {
                    GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.CustomerOrderNumber)
                };
                var customerOrderNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber;

                var account = CL1_USR.ORM_USR_Account.Query.Search(Connection, Transaction, new CL1_USR.ORM_USR_Account.Query
                {
                    USR_AccountID = securityTicket.AccountID,
                    IsDeleted     = false,
                    Tenant_RefID  = securityTicket.TenantID
                }).Single();

                var orderedStatusID = CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
                                                                                                new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Status.Query
                {
                    GlobalPropertyMatchingID = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(DLCore_DBCommons.APODemand.ECustomerOrderStatus.Ordered),
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).Single().ORD_CUO_CustomerOrder_StatusID;

                #endregion

                #region Customer Order Header Creation
                header = new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Header
                {
                    ORD_CUO_CustomerOrder_HeaderID = Guid.NewGuid(),
                    Tenant_RefID       = securityTicket.TenantID,
                    Creation_Timestamp = DateTime.Now,
                    CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID,
                    Current_CustomerOrderStatus_RefID   = orderedStatusID,
                    CustomerOrder_Number         = customerOrderNumber,
                    CustomerOrder_Currency_RefID = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result.CMN_CurrencyID
                };
                header.ProcurementOrderITL  = Guid.Empty.ToString();
                header.TotalValue_BeforeTax = 0.0M;
                #endregion

                #region CustomerOrderStatusHistory
                var statusHistory = new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_StatusHistory
                {
                    ORD_CUO_CustomerOrder_StatusHistoryID = Guid.NewGuid(),
                    Creation_Timestamp                    = DateTime.Now,
                    Tenant_RefID                          = securityTicket.TenantID,
                    CustomerOrder_Header_RefID            = header.ORD_CUO_CustomerOrder_HeaderID,
                    CustomerOrder_Status_RefID            = orderedStatusID,
                    StatusHistoryComment                  = null,
                    PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID,
                };
                statusHistory.Save(Connection, Transaction);
                #endregion

                #region Create and Save CustomerInteraction

                var incrCustIntrNumberParam = new P_L2NR_GaIINfUA_1454()
                {
                    GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.CustomerInteractionNumber)
                };
                var customerInteractionNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrCustIntrNumberParam, securityTicket).Result.Current_IncreasingNumber;

                customerInteraction = new ORM_CMN_POS_CustomerInteraction()
                {
                    CMN_POS_CustomerInteractionID = Guid.NewGuid(),
                    Creation_Timestamp            = DateTime.Now,
                    IsCustomerOrderInteraction    = true,
                    CustomerOrderHeader_RefID     = header.ORD_CUO_CustomerOrder_HeaderID,
                    CustomerInteractionNumber     = customerInteractionNumber,
                    DateOfCustomerInteraction     = DateTime.Now,
                    Tenant_RefID = securityTicket.TenantID
                };
                customerInteraction.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                var fetched = header.Load(Connection, Transaction, Parameter.CustomerOrderHeaderID);
                if (fetched.Status != FR_Status.Success || header.ORD_CUO_CustomerOrder_HeaderID != Parameter.CustomerOrderHeaderID)
                {
                    returnValue.ErrorMessage = fetched.ErrorMessage;
                    returnValue.Status       = FR_Status.Error_Internal;
                    returnValue.Result       = null;
                    return(returnValue);
                }

                #region Update Customer Order Total Value
                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 = Parameter.CustomerOrderHeaderID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });
                header.TotalValue_BeforeTax = positions.Sum(x => x.Position_ValueTotal);
                #endregion

                #region Load CustomerInteraction
                customerInteraction = ORM_CMN_POS_CustomerInteraction.Query.Search(
                    Connection,
                    Transaction,
                    new ORM_CMN_POS_CustomerInteraction.Query()
                {
                    CustomerOrderHeader_RefID = header.ORD_CUO_CustomerOrder_HeaderID,
                    Tenant_RefID = securityTicket.TenantID
                }).FirstOrDefault();
                #endregion
            }

            if (Parameter.OrganizationalUnitID != null)
            {
                Guid ucdID = Guid.Empty;

                //var ucd = CL1_CMN.ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction,
                //    new CL1_CMN.ORM_CMN_UniversalContactDetail.Query
                //    {
                //        CMN_UniversalContactDetailID = ucdID,
                //        IsDeleted = false,
                //        Tenant_RefID = securityTicket.TenantID
                //    });
                // header.ShippingAddressUCD_RefID =
            }

            header.CustomerOrder_Date = Parameter.CustomerOrderDate;
            header.DeliveryDeadline   = Parameter.DeliveryDeadline;
            header.OrderingCustomer_BusinessParticipant_RefID = Parameter.Customer_BusinessParticipantID;
            header.Save(Connection, Transaction);

            returnValue.Result = new L5CO_COH_1326()
            {
                CustomerOrderHeaderId  = header.ORD_CUO_CustomerOrder_HeaderID,
                CustomerInteractionsId = customerInteraction == null ? Guid.Empty : customerInteraction.CMN_POS_CustomerInteractionID
            };
            return(returnValue);

            #endregion UserCode
        }