protected static FR_L3PR_IoUPfSC_1326_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L3PR_IoUPfSC_1326 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3PR_IoUPfSC_1326_Array();

            //Put your code here
            var importedProducts = new List <L3PR_IoUPfSC_1326>();

            #region ImportOrUpdate Product's BaseData
            P_L3PR_IoUPBD_1614 param = new P_L3PR_IoUPBD_1614();
            param.Products = Parameter.Products.Select(i => i.Product).ToArray();
            var importedProductsBaseData = cls_ImportOrUpdate_Products_BaseData.Invoke(Connection, Transaction, param, securityTicket).Result;
            #endregion

            //TODO: for each product saved, create or update product_2_productGroup
            foreach (var importedProductBaseData in importedProductsBaseData)
            {
                var currentParameter = Parameter.Products.SingleOrDefault(i => i.Product.ProductITL == importedProductBaseData.ProductITL);

                var product = new ORM_CMN_PRO_Product();
                product.Load(Connection, Transaction, importedProductBaseData.ProductID);

                if (!importedProductBaseData.IsAlreadyExisted)
                {
                    product.IfImportedFromExternalCatalog_CatalogSubscription_RefID = Parameter.SubscribedCatalogID;
                    product.IsImportedFromExternalCatalog = true;
                    product.Save(Connection, Transaction);

                    ORM_CMN_PRO_Product_2_ProductGroup product_2_productGroup = new ORM_CMN_PRO_Product_2_ProductGroup();
                    product_2_productGroup.CMN_PRO_Product_RefID      = product.CMN_PRO_ProductID;
                    product_2_productGroup.CMN_PRO_ProductGroup_RefID = Parameter.ProductGroupID;
                    product_2_productGroup.Tenant_RefID       = securityTicket.TenantID;
                    product_2_productGroup.Creation_Timestamp = DateTime.Now;
                    product_2_productGroup.Save(Connection, Transaction);
                }
                else
                {
                    #region Update Product_2_ProductGroup
                    var isAlreadyInGroup = ORM_CMN_PRO_Product_2_ProductGroup.Query.Exists(Connection, Transaction, new ORM_CMN_PRO_Product_2_ProductGroup.Query()
                    {
                        CMN_PRO_Product_RefID      = product.CMN_PRO_ProductID,
                        CMN_PRO_ProductGroup_RefID = Parameter.ProductGroupID,
                        Tenant_RefID = securityTicket.TenantID
                    });

                    if (!isAlreadyInGroup)
                    {
                        ORM_CMN_PRO_Product_2_ProductGroup product_2_productGroup = new ORM_CMN_PRO_Product_2_ProductGroup();
                        product_2_productGroup.CMN_PRO_Product_RefID      = product.CMN_PRO_ProductID;
                        product_2_productGroup.CMN_PRO_ProductGroup_RefID = Parameter.ProductGroupID;
                        product_2_productGroup.Tenant_RefID       = securityTicket.TenantID;
                        product_2_productGroup.Creation_Timestamp = DateTime.Now;
                        product_2_productGroup.Save(Connection, Transaction);
                    }
                    #endregion
                }

                #region Default Price

                var price = ORM_CMN_SLS_Price.Query.Search(Connection, Transaction, new ORM_CMN_SLS_Price.Query()
                {
                    PricelistRelease_RefID = Parameter.PriceListReleaseID,
                    CMN_PRO_Product_RefID  = product.CMN_PRO_ProductID,
                    Tenant_RefID           = securityTicket.TenantID,
                    CMN_Currency_RefID     = Parameter.CatalogCurrencyID,
                    IsDeleted = false
                }).SingleOrDefault();

                if (price == null)
                {
                    price = new ORM_CMN_SLS_Price();
                    price.CMN_SLS_PriceID        = Guid.NewGuid();
                    price.PricelistRelease_RefID = Parameter.PriceListReleaseID;
                    price.CMN_PRO_Product_RefID  = product.CMN_PRO_ProductID;
                    price.CMN_Currency_RefID     = Parameter.CatalogCurrencyID;
                    price.Tenant_RefID           = securityTicket.TenantID;
                    price.Creation_Timestamp     = DateTime.Now;
                }

                price.PriceAmount = currentParameter.Price;
                price.Save(Connection, Transaction);

                #endregion

                importedProducts.Add(new L3PR_IoUPfSC_1326()
                {
                    ProductID  = product.CMN_PRO_ProductID,
                    ProductITL = product.ProductITL
                });
            }

            returnValue.Result = importedProducts.ToArray();

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3PR_IoUPBD_1614_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L3PR_IoUPBD_1614 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L3PR_IoUPBD_1614_Array();
            var result      = new List <L3PR_IoUPBD_1614>();

            //Put your code here

            #region Get All Producers for Tenant

            var allProducers = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            });

            #endregion

            #region Get Taxes For Default Country

            var taxesToImport = Parameter.Products.Select(i => i.VAT).Distinct();

            var param = new P_L3TX_STfDCaRR_1119();
            param.TaxRates = taxesToImport.ToArray();
            var allTaxes = cls_Save_Taxes_for_DefaultCountry_and_ReturnResult.Invoke(Connection, Transaction, param, securityTicket).Result;

            #endregion

            foreach (var item in Parameter.Products)
            {
                bool alreadyExistingInDB = true;

                #region ORM_CMN_PRO_Product
                var productQuery = new ORM_CMN_PRO_Product.Query();
                productQuery.ProductITL   = item.ProductITL;
                productQuery.Tenant_RefID = securityTicket.TenantID;
                productQuery.IsDeleted    = false;
                productQuery.IsProductAvailableForOrdering = true;

                var product = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, productQuery).FirstOrDefault();

                if (product == null)
                {
                    product = new ORM_CMN_PRO_Product();
                    product.CMN_PRO_ProductID  = Guid.NewGuid();
                    product.ProductITL         = item.ProductITL;
                    product.PackageInfo_RefID  = Guid.NewGuid();
                    product.Creation_Timestamp = DateTime.Now;
                    product.Tenant_RefID       = securityTicket.TenantID;

                    alreadyExistingInDB = false;
                }

                product.Product_Name                  = item.Product_Name;
                product.Product_Description           = item.Product_Description;
                product.Product_Number                = item.Product_Number;
                product.IsProduct_Article             = true;
                product.IsProductAvailableForOrdering = true;

                #region Save Producer
                var producerBPT = allProducers.Where(i => i.DisplayName == item.Producer).FirstOrDefault();

                if (producerBPT == default(ORM_CMN_BPT_BusinessParticipant))
                {
                    producerBPT = new ORM_CMN_BPT_BusinessParticipant();
                    producerBPT.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                    producerBPT.DisplayName        = item.Producer;
                    producerBPT.IsCompany          = true;
                    producerBPT.Tenant_RefID       = securityTicket.TenantID;
                    producerBPT.Creation_Timestamp = DateTime.Now;
                    producerBPT.Save(Connection, Transaction);
                }

                #endregion

                product.ProducingBusinessParticipant_RefID = producerBPT.CMN_BPT_BusinessParticipantID;
                product.Save(Connection, Transaction);
                #endregion

                #region Unit
                //Unit could be used for multiple products, there is no sense to edit unit
                //If there is need to change unit, we should find unit with that iso code and change reference

                var unitsQuery = new ORM_CMN_Unit.Query();
                unitsQuery.Tenant_RefID = securityTicket.TenantID;
                unitsQuery.ISOCode      = item.MeasuredInUnit_ISO_um_ums;
                unitsQuery.IsDeleted    = false;

                var measuredInUnit = ORM_CMN_Unit.Query.Search(Connection, Transaction, unitsQuery).FirstOrDefault();
                if (measuredInUnit == null)
                {
                    measuredInUnit = new ORM_CMN_Unit();
                    measuredInUnit.Tenant_RefID       = securityTicket.TenantID;
                    measuredInUnit.Creation_Timestamp = DateTime.Now;
                    measuredInUnit.ISOCode            = item.MeasuredInUnit_ISO_um_ums;
                    measuredInUnit.CMN_UnitID         = Guid.NewGuid();
                    measuredInUnit.Save(Connection, Transaction);
                }
                #endregion

                #region PackageInfo
                var packageInfo = new ORM_CMN_PRO_PAC_PackageInfo();
                packageInfo.Load(Connection, Transaction, product.PackageInfo_RefID);
                if (packageInfo.CMN_PRO_PAC_PackageInfoID == Guid.Empty)
                {
                    packageInfo.CMN_PRO_PAC_PackageInfoID = product.PackageInfo_RefID;
                    packageInfo.Creation_Timestamp        = DateTime.Now;
                    packageInfo.Tenant_RefID = securityTicket.TenantID;
                }
                packageInfo.PackageContent_DisplayLabel         = item.Amount;
                packageInfo.PackageContent_Amount               = PackageAmountUtils.GetPackageAmount(item.Amount);
                packageInfo.PackageContent_MeasuredInUnit_RefID = measuredInUnit.CMN_UnitID;

                packageInfo.Save(Connection, Transaction);
                #endregion

                #region VAT
                var salesTax = ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query()
                {
                    Product_RefID = product.CMN_PRO_ProductID,
                    Tenant_RefID  = securityTicket.TenantID,
                    IsDeleted     = false
                }).FirstOrDefault();

                if (salesTax == null)
                {
                    salesTax = new ORM_CMN_PRO_Product_SalesTaxAssignmnet();
                    salesTax.CMN_PRO_Product_SalesTaxAssignmnetID = Guid.NewGuid();
                    salesTax.Product_RefID      = product.CMN_PRO_ProductID;
                    salesTax.Creation_Timestamp = DateTime.Now;
                    salesTax.Tenant_RefID       = securityTicket.TenantID;
                }

                salesTax.ApplicableSalesTax_RefID = allTaxes.Where(i => i.TaxRate == item.VAT).Select(j => j.TaxID).FirstOrDefault();
                salesTax.Save(Connection, Transaction);
                #endregion

                result.Add(new L3PR_IoUPBD_1614()
                {
                    ProductITL       = product.ProductITL,
                    ProductID        = product.CMN_PRO_ProductID,
                    IsAlreadyExisted = alreadyExistingInDB
                });
            }

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

            FR_L3PR_IoUPBD_1614_Array functionReturn = new FR_L3PR_IoUPBD_1614_Array();

            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_ImportOrUpdate_Products_BaseData", ex);
            }
            return(functionReturn);
        }
 ///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_L3PR_IoUPBD_1614_Array Invoke(string ConnectionString, P_L3PR_IoUPBD_1614 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }