/// <summary> /// Deletes the catalog node. /// </summary> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="catalogId">The catalog id.</param> internal static void DeleteCatalogNode(int catalogNodeId, int catalogId) { CatalogNodeDto catalogNodeDto = GetCatalogNodesDto(catalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull)); CatalogRelationDto catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(0, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogNode | CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); DeleteNodeRecursive(catalogNodeId, catalogId, ref catalogNodeDto, ref catalogRelationDto); if (catalogRelationDto.HasChanges()) { CatalogRelationManager.SaveCatalogRelation(catalogRelationDto); } if (catalogNodeDto.HasChanges()) { SaveCatalogNode(catalogNodeDto); } }
/// <summary> /// Deletes the entry. /// </summary> /// <param name="entryId">The entry id.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> internal static void DeleteCatalogEntry(int entryId, bool recursive) { CatalogEntryDto catalogEntryDto = GetCatalogEntryDto(entryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (catalogEntryDto.CatalogEntry.Count > 0) { if (recursive) { //Delete child entry rows CatalogEntryDto childrenDto = GetCatalogEntriesDto(entryId, String.Empty, String.Empty, new CatalogEntryResponseGroup()); foreach (CatalogEntryDto.CatalogEntryRow row in childrenDto.CatalogEntry) { DeleteCatalogEntry(row.CatalogEntryId, recursive); } } CatalogRelationDto catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(0, 0, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry)); //Delete NodeEntryRelation rows foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows) { row.Delete(); } //Delete CatalogEntryRelation rows foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows) { row.Delete(); } if (catalogRelationDto.HasChanges()) { CatalogRelationManager.SaveCatalogRelation(catalogRelationDto); } //Delete CatalogEntryAssociation rows foreach (CatalogEntryDto.CatalogAssociationRow catalogAssociationRow in catalogEntryDto.CatalogAssociation) { CatalogAssociationDto catalogAssociationDto = CatalogAssociationManager.GetCatalogAssociationDto(catalogAssociationRow.CatalogAssociationId); foreach (CatalogAssociationDto.CatalogEntryAssociationRow itemCatalogEntryAssociation in catalogAssociationDto.CatalogEntryAssociation) { itemCatalogEntryAssociation.Delete(); } if (catalogAssociationDto.HasChanges()) { CatalogAssociationManager.SaveCatalogAssociation(catalogAssociationDto); } } CatalogEntryDto.CatalogEntryRow entryRow = catalogEntryDto.CatalogEntry[0]; // Delete inventory if on exists if (entryRow.InventoryRow != null) { entryRow.InventoryRow.Delete(); } //Delete entry row entryRow.Delete(); SaveCatalogEntry(catalogEntryDto); } }
/// <summary> /// Deletes the catalog. /// </summary> /// <param name="catalogId">The catalog id.</param> public static void DeleteCatalog(int catalogId) { CatalogDto dto = GetCatalogDto(catalogId, new CatalogResponseGroup(CatalogResponseGroup.ResponseGroup.CatalogFull)); if (dto.Catalog.Count == 0) { return; } //Delete CatalogItemAsset rows by CatalogId CatalogNodeDto catalogNodeDto = CatalogNodeManager.GetCatalogNodesDto(catalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.Assets)); if (catalogNodeDto.CatalogNode.Count > 0) { for (int i1 = 0; i1 < catalogNodeDto.CatalogItemAsset.Count; i1++) { catalogNodeDto.CatalogItemAsset[i1].Delete(); } CatalogNodeManager.SaveCatalogNode(catalogNodeDto); } // delete relations CatalogRelationDto catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(catalogId, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogNode)); foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows) { row.Delete(); } foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows) { row.Delete(); } foreach (CatalogRelationDto.CatalogNodeRelationRow row in catalogRelationDto.CatalogNodeRelation.Rows) { row.Delete(); } if (catalogRelationDto.HasChanges()) { CatalogRelationManager.SaveCatalogRelation(catalogRelationDto); } //Delete CatalogItemSeo rows by CatalogNodeId and CatalogNode rows catalogNodeDto = CatalogNodeManager.GetCatalogNodesDto(catalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull)); if (catalogNodeDto.CatalogNode.Count > 0) { for (int i1 = 0; i1 < catalogNodeDto.CatalogItemSeo.Count; i1++) { catalogNodeDto.CatalogItemSeo[i1].Delete(); } for (int i1 = 0; i1 < catalogNodeDto.CatalogNode.Count; i1++) { catalogNodeDto.CatalogNode[i1].Delete(); } CatalogNodeManager.SaveCatalogNode(catalogNodeDto); } //Delete entries while (true) { CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.Namespace = String.Empty; options.RecordsToRetrieve = 100; options.StartingRecord = 0; pars.CatalogNames.Add(dto.Catalog[0].Name); int totalCount = 0; CatalogEntryDto catalogEntryDto = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); //Delete CatalogEntryAssociation rows foreach (CatalogEntryDto.CatalogAssociationRow catalogAssociationRow in catalogEntryDto.CatalogAssociation) { CatalogAssociationDto catalogAssociationDto = FrameworkContext.Current.CatalogSystem.GetCatalogAssociationDto(catalogAssociationRow.CatalogAssociationId); foreach (CatalogAssociationDto.CatalogEntryAssociationRow itemCatalogEntryAssociation in catalogAssociationDto.CatalogEntryAssociation) { itemCatalogEntryAssociation.Delete(); } if (catalogAssociationDto.HasChanges()) { CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto); } } //Delete CatalogEntry rows foreach (CatalogEntryDto.CatalogEntryRow catalogEntryRow in catalogEntryDto.CatalogEntry) { if (catalogEntryRow.InventoryRow != null) { catalogEntryRow.InventoryRow.Delete(); } catalogEntryRow.Delete(); } CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); // Break the loop if we retrieved all the record if (totalCount < options.RecordsToRetrieve) { break; } } // Delete root entries CatalogEntryDto rootCatalogEntries = CatalogEntryManager.GetCatalogEntriesDto(catalogId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); foreach (CatalogEntryDto.CatalogEntryRow catalogEntryRow in rootCatalogEntries.CatalogEntry) { if (catalogEntryRow.InventoryRow != null) { catalogEntryRow.InventoryRow.Delete(); } catalogEntryRow.Delete(); } CatalogEntryManager.SaveCatalogEntry(rootCatalogEntries); //Delete Catalog row by id dto.Catalog[0].Delete(); SaveCatalog(dto); }