protected static FR_L5CA_APtPG_1137_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_APtPG_1137 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L5CA_APtPG_1137_Array(); //Put your code here List <L5CA_APtPG_1137> returnList = new List <L5CA_APtPG_1137>(); foreach (var ProductITL in Parameter.Products) { ORM_CMN_PRO_Product.Query prodQuery = new ORM_CMN_PRO_Product.Query() { ProductITL = ProductITL, IsDeleted = false, Tenant_RefID = securityTicket.TenantID, IsProductAvailableForOrdering = true }; var prod = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, prodQuery).Single(); ORM_CMN_PRO_Catalog_Product.Query catalogProductQuery = new ORM_CMN_PRO_Catalog_Product.Query() { CMN_PRO_Product_RefID = prod.CMN_PRO_ProductID, CMN_PRO_Catalog_Revision_RefID = Parameter.CatalogRevision_ID, IsDeleted = false }; if (ORM_CMN_PRO_Catalog_Product.Query.Exists(Connection, Transaction, catalogProductQuery)) { String GroupName = "Catalogue root"; ORM_CMN_PRO_Catalog_ProductGroup catGroup = new ORM_CMN_PRO_Catalog_ProductGroup(); if (Parameter.Product_Group_ID != Guid.Empty) { catGroup.Load(Connection, Transaction, Parameter.Product_Group_ID); GroupName = catGroup.CatalogProductGroup_Name; } L5CA_APtPG_1137 item = new L5CA_APtPG_1137() { CatalgueProductGroup = GroupName, Product_Name = prod.Product_Name }; returnList.Add(item); continue; // catalog group for the product already exists in catalog revision } // Create catalog product ORM_CMN_PRO_Catalog_Product newCp = new ORM_CMN_PRO_Catalog_Product(); newCp.CMN_PRO_Product_RefID = prod.CMN_PRO_ProductID; newCp.CMN_PRO_Catalog_ProductID = Guid.NewGuid(); newCp.Tenant_RefID = securityTicket.TenantID; newCp.CMN_PRO_Catalog_Revision_RefID = Parameter.CatalogRevision_ID; // Create catalog product 2 product group (Product group already exists) if there is group id in Parameter else only add to catalog if (Parameter.Product_Group_ID != Guid.Empty) { ORM_CMN_PRO_Catalog_Product_2_ProductGroup prodToGroup = new ORM_CMN_PRO_Catalog_Product_2_ProductGroup(); prodToGroup.CMN_PRO_Catalog_Product_RefID = newCp.CMN_PRO_Catalog_ProductID; prodToGroup.CMN_PRO_Catalog_ProductGroup_RefID = Parameter.Product_Group_ID; prodToGroup.Tenant_RefID = securityTicket.TenantID; prodToGroup.Save(Connection, Transaction); } newCp.Save(Connection, Transaction); } returnValue.Result = returnList.ToArray(); 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_L5CA_APtPG_1137_Array Invoke(DbConnection Connection, DbTransaction Transaction, P_L5CA_APtPG_1137 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { return(Invoke(Connection, Transaction, null, Parameter, securityTicket)); }
///<summary> /// Method Invocation of wrapper classes ///<summary> protected static FR_L5CA_APtPG_1137_Array Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5CA_APtPG_1137 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { bool cleanupConnection = Connection == null; bool cleanupTransaction = Transaction == null; FR_L5CA_APtPG_1137_Array functionReturn = new FR_L5CA_APtPG_1137_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_Add_Product_to_ProductGroup", ex); } return(functionReturn); }
///<summary> /// Opens the connection/transaction for the given connectionString, and closes them when complete ///<summary> public static FR_L5CA_APtPG_1137_Array Invoke(string ConnectionString, P_L5CA_APtPG_1137 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { return(Invoke(null, null, ConnectionString, Parameter, securityTicket)); }