/// <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> /// Loads the entry. /// </summary> /// <param name="row">The row.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <param name="responseGroup">The response group.</param> /// <param name="entryList">The entry list.</param> /// <returns></returns> internal static Entry LoadEntry(CatalogEntryDto.CatalogEntryRow row, bool recursive, CatalogEntryResponseGroup responseGroup, ref StringCollection entryList) { Entry entry = null; // Load entry if (row != null) { // Track entries added, to avoid circular dependencies entryList.Add(row.Code); entry = new Entry(row); // Populate association detailed info if (recursive && (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Associations))) { if (entry.Associations != null) { CatalogAssociationDto associationDto = CatalogAssociationManager.GetCatalogAssociationDtoByEntryId(row.CatalogEntryId); // If associations do not contain any entries, then we do not need to go through the rest if (associationDto.CatalogEntryAssociation.Count > 0) { foreach (Association association in entry.Associations) { int associationId = 0; // Find out association id foreach (CatalogAssociationDto.CatalogAssociationRow associationRow in associationDto.CatalogAssociation) { if (associationRow.AssociationName.Equals(association.Name)) { associationId = associationRow.CatalogAssociationId; break; } } // Load association entries List <EntryAssociation> entryAssociationList = new List <EntryAssociation>(); CatalogEntryDto associatedEntries = GetAssociatedCatalogEntriesDto(row.CatalogEntryId, association.Name, responseGroup); foreach (CatalogEntryDto.CatalogEntryRow childRow in associatedEntries.CatalogEntry) { EntryAssociation entryAssociation = new EntryAssociation(); // Find appropriate row CatalogAssociationDto.CatalogEntryAssociationRow entryAssociationRow = associationDto.CatalogEntryAssociation.FindByCatalogAssociationIdCatalogEntryId(associationId, childRow.CatalogEntryId); if (entryAssociationRow != null) { entryAssociation.SortOrder = entryAssociationRow.SortOrder; entryAssociation.AssociationType = entryAssociationRow.AssociationTypeId; entryAssociation.AssociationDesc = entryAssociationRow.AssociationTypeRow.Description; } // Check for circular dependencies here /* * if (row.CatalogEntryId == childRow.CatalogEntryId) * throw new CircularDependencyException(String.Format("Circular dependency detected. Entry association \"{0}\" for \"{1}[{2}]\" contains reference to itself.", entryAssociation.AssociationDesc, childRow.Name, childRow.CatalogEntryId)); * */ bool loadRecursive = recursive; // do not load recursive if there is potential circular dependency if (entryList.Contains(row.Code)) { loadRecursive = false; } Entry childEntry = LoadEntry(childRow, loadRecursive, responseGroup, ref entryList); childEntry.ParentEntry = null; entryAssociation.Entry = childEntry; entryAssociationList.Add(entryAssociation); } association.EntryAssociations = new EntryAssociations(); association.EntryAssociations.Association = entryAssociationList.ToArray(); } } } } // Populate children if (recursive && (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Children))) { bool loadRecursive = recursive; // do not load recursive if there is potential circular dependency if (entryList.Contains(row.Code)) { loadRecursive = false; } CatalogEntryDto childrenDto = GetCatalogEntriesDto(row.CatalogEntryId, String.Empty, String.Empty, responseGroup); Entries entries = LoadEntries(childrenDto, entry, loadRecursive, responseGroup, ref entryList); entry.Entries = entries; } } /* * else * entry = new Entry(); * */ return(entry); }