Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes the entry recursive.
        /// </summary>
        /// <param name="entryId">The entry id.</param>
        /// <param name="parentCatalogId">The parent catalog id.</param>
        /// <param name="parentCatalogNodeId">The parent catalog node id.</param>
        private void DeleteEntryRecursive(int entryId, int parentCatalogId, int parentCatalogNodeId)
        {
            CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            if (catalogEntryDto.CatalogEntry.Count > 0)
            {
                bool deleteEntry = true;                 // flag which will determine if we are deleting an entry

                //Delete NodeEntryRelation rows
                CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                int totalRelations = catalogRelationDto.NodeEntryRelation.Count;
                foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                {
                    if (row.CatalogId == parentCatalogId && row.CatalogNodeId == parentCatalogNodeId)
                    {
                        row.Delete();
                        totalRelations--;
                    }
                    else if (parentCatalogId == catalogEntryDto.CatalogEntry[0].CatalogId && parentCatalogNodeId == 0)                     // delete other catalog relationship if we deleting entry in primary catalog the entry belongs to and we deleting from the very root of catalog
                    {
                        row.Delete();
                        totalRelations--;
                    }
                }

                if (catalogRelationDto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);
                }

                // Do not delete if there are more than 1 relationships or if the current catalog is not the primary one
                if (totalRelations > 0 || parentCatalogId != catalogEntryDto.CatalogEntry[0].CatalogId)
                {
                    deleteEntry = false;
                }

                if (deleteEntry)
                {
                    //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 relations with all sub entries
                    CatalogRelationDto relation = CatalogContext.Current.GetCatalogRelationDto(parentCatalogId, parentCatalogNodeId, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));
                    foreach (CatalogRelationDto.CatalogEntryRelationRow relationRow in relation.CatalogEntryRelation)
                    {
                        relationRow.Delete();
                    }
                    CatalogContext.Current.SaveCatalogRelationDto(relation);

                    CatalogEntryDto.CatalogEntryRow entryRow = catalogEntryDto.CatalogEntry[0];

                    // Delete inventory if on exists
                    if (entryRow.InventoryRow != null)
                    {
                        entryRow.InventoryRow.Delete();
                    }

                    //Delete entry row
                    entryRow.Delete();
                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                }
            }
        }