///<summary> /// Method Invocation of wrapper classes ///<summary> protected static FR_L5CA_PNCV_1520 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5CA_PNCV_1520 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { bool cleanupConnection = Connection == null; bool cleanupTransaction = Transaction == null; FR_L5CA_PNCV_1520 functionReturn = new FR_L5CA_PNCV_1520(); 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_Publish_NewCatalogVersion", ex); } return(functionReturn); }
protected static FR_L5CA_PNCV_1520 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_PNCV_1520 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_L5CA_PNCV_1520(); returnValue.Result = new L5CA_PNCV_1520(); //Put your code here var account = new ORM_USR_Account(); account.Load(Connection, Transaction, securityTicket.AccountID); #region Update active catalog revision ORM_CMN_PRO_Catalog_Revision rev = new ORM_CMN_PRO_Catalog_Revision(); rev.Load(Connection, Transaction, Parameter.CMN_PRO_Catalog_RevisionID); rev.Valid_From = Parameter.Valid_From; rev.Valid_Through = Parameter.Valid_Through; rev.Default_PricelistRelease_RefID = Parameter.Default_PricelistRelease_RefID; rev.PublishedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID; rev.PublishedOn_Date = DateTime.Now; rev.Save(Connection, Transaction); #endregion #region Update catalog public/private status if (rev.RevisionNumber == 1) { ORM_CMN_PRO_Catalog catalog = new ORM_CMN_PRO_Catalog(); catalog.Load(Connection, Transaction, rev.CMN_PRO_Catalog_RefID); catalog.IsPublicCatalog = Parameter.IsPublic; catalog.Save(Connection, Transaction); } #endregion #region Create new catalog revision ORM_CMN_PRO_Catalog_Revision newRev = new ORM_CMN_PRO_Catalog_Revision(); newRev.CMN_PRO_Catalog_RevisionID = Guid.NewGuid(); newRev.CMN_PRO_Catalog_RefID = rev.CMN_PRO_Catalog_RefID; newRev.Tenant_RefID = securityTicket.TenantID; newRev.Creation_Timestamp = DateTime.Now; newRev.CatalogRevision_Description = "Revision for Catalog"; newRev.CatalogRevision_Name = "New Catalog Revision"; newRev.IsDeleted = false; newRev.RevisionNumber = rev.RevisionNumber + 1; newRev.Save(Connection, Transaction); #endregion #region Products var oldProducts = ORM_CMN_PRO_Catalog_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product.Query() { CMN_PRO_Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); if (oldProducts.Count == 0) { returnValue.Result.Status_Code = -1; // -1 no products in revision returnValue.Result.Status_Message = "no products in revision"; return(returnValue); } //oldProductID - newProductID Dictionary <Guid, Guid> productsMapping = new Dictionary <Guid, Guid>(); var productsWithoutPrices = ProductWithoutPrices(Connection, Transaction, Parameter, securityTicket, oldProducts); if (productsWithoutPrices.Count > 0) { returnValue.Result.Status_Code = -2; // -2 => pricelist does not have price for product returnValue.Result.Status_Message = JsonConvert.SerializeObject(productsWithoutPrices); return(returnValue); } foreach (var item in oldProducts) { var newProduct = new ORM_CMN_PRO_Catalog_Product() { CMN_PRO_Catalog_ProductID = Guid.NewGuid(), CMN_PRO_Product_Variant_RefID = item.CMN_PRO_Product_Variant_RefID, Creation_Timestamp = DateTime.Now, Tenant_RefID = item.Tenant_RefID, CMN_PRO_Catalog_Revision_RefID = newRev.CMN_PRO_Catalog_RevisionID, CMN_PRO_Product_RefID = item.CMN_PRO_Product_RefID, }; newProduct.Save(Connection, Transaction); productsMapping.Add(item.CMN_PRO_Catalog_ProductID, newProduct.CMN_PRO_Catalog_ProductID); } #endregion #region ProductGroups var oldGroups = ORM_CMN_PRO_Catalog_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_ProductGroup.Query() { Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID, IsDeleted = false }); //oldGroupID - newGroupID Dictionary <Guid, Guid> groupsMapping = new Dictionary <Guid, Guid>(); groupsMapping.Add(Guid.Empty, Guid.Empty); foreach (var item in oldGroups) { groupsMapping.Add(item.CMN_PRO_Catalog_ProductGroupID, Guid.NewGuid()); } foreach (var item in oldGroups) { var newGroup = new ORM_CMN_PRO_Catalog_ProductGroup() { CMN_PRO_Catalog_ProductGroupID = groupsMapping[item.CMN_PRO_Catalog_ProductGroupID], Catalog_Revision_RefID = newRev.CMN_PRO_Catalog_RevisionID, CatalogProductGroup_Name = item.CatalogProductGroup_Name, CatalogProductGroup_Parent_RefID = groupsMapping[item.CatalogProductGroup_Parent_RefID], Creation_Timestamp = DateTime.Now, Tenant_RefID = item.Tenant_RefID }; newGroup.Save(Connection, Transaction); var oldProductsInGroup = ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query() { CMN_PRO_Catalog_ProductGroup_RefID = item.CMN_PRO_Catalog_ProductGroupID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); foreach (var product in oldProductsInGroup) { if (groupsMapping.ContainsKey(product.CMN_PRO_Catalog_ProductGroup_RefID) && productsMapping.ContainsKey(product.CMN_PRO_Catalog_Product_RefID)) { var newProduct = new ORM_CMN_PRO_Catalog_Product_2_ProductGroup() { AssignmentID = Guid.NewGuid(), CMN_PRO_Catalog_ProductGroup_RefID = groupsMapping[product.CMN_PRO_Catalog_ProductGroup_RefID], CMN_PRO_Catalog_Product_RefID = productsMapping[product.CMN_PRO_Catalog_Product_RefID], Creation_Timestamp = DateTime.Now, Tenant_RefID = item.Tenant_RefID }; newProduct.Save(Connection, Transaction); } } } #endregion returnValue.Result.Status_Code = 1; returnValue.Result.Status_Message = "Success"; returnValue.Result.ID = newRev.CMN_PRO_Catalog_RevisionID; return(returnValue); #endregion UserCode }