/// <summary>
        /// Deletes the entry recursive.
        /// </summary>
        /// <param name="entryId">The entry id.</param>
        /// <param name="parentCatalogId">The parent catalog id.</param>
        private void DeleteEntryRecursive(int entryId, int parentCatalogId)
        {
            CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            if (catalogEntryDto.CatalogEntry.Count > 0)
            {
                //Delete NodeEntryRelation rows
                CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                {
                    if (row.CatalogId == parentCatalogId)
                    {
                        row.Delete();
                    }
                }

                if (catalogRelationDto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);
                }
                else                 //if NodeEntryRelation doesn't exist delete entry
                {
                    //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 child entry rows
                    CatalogEntryDto childrenDto = CatalogContext.Current.GetCatalogEntriesDto(entryId, String.Empty, String.Empty);
                    foreach (CatalogEntryDto.CatalogEntryRow row in childrenDto.CatalogEntry)
                    {
                        DeleteEntryRecursive(row.CatalogEntryId, 0);
                    }

                    //Delete entry row
                    catalogEntryDto.CatalogEntry[0].Delete();
                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                }
            }
        }
        /// <summary>
        /// Clones the node entry.
        /// </summary>
        /// <param name="catalogId">The catalog id.</param>
        /// <param name="catalogNodeId">The catalog node id.</param>
        /// <param name="catalogEntryId">The catalog entry id.</param>
        /// <param name="targetCatalogId">The target catalog id.</param>
        /// <param name="targetCatalogNodeId">The target catalog node id.</param>
        private void CloneNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    if (catalogId <= 0)
                    {
                        catalogId = catalogEntryDto.CatalogEntry[0].CatalogId;
                    }

                    if (targetCatalogId <= 0)
                    {
                        targetCatalogId = catalogId;
                    }

                    CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));

                    CatalogAssociationDto catalogAssociationDto = CatalogContext.Current.GetCatalogAssociationDtoByEntryId(catalogEntryId);

                    CatalogEntryDto newCatalogEntryDto = new CatalogEntryDto();
                    newCatalogEntryDto.CatalogEntry.ImportRow(catalogEntryDto.CatalogEntry[0]);
                    newCatalogEntryDto.CatalogEntry[0].SetAdded();
                    newCatalogEntryDto.CatalogEntry[0].Code = Guid.NewGuid().ToString();

                    if (catalogEntryDto.CatalogItemSeo.Count > 0)
                    {
                        foreach (CatalogEntryDto.CatalogItemSeoRow row in catalogEntryDto.CatalogItemSeo.Rows)
                        {
                            newCatalogEntryDto.CatalogItemSeo.ImportRow(row);
                            newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].SetAdded();
                            newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx";
                        }
                    }

                    if (catalogEntryDto.Variation.Count > 0)
                    {
                        foreach (CatalogEntryDto.VariationRow row in catalogEntryDto.Variation.Rows)
                        {
                            newCatalogEntryDto.Variation.ImportRow(row);
                            newCatalogEntryDto.Variation[newCatalogEntryDto.Variation.Count - 1].SetAdded();
                        }
                    }

                    if (catalogEntryDto.SalePrice.Count > 0)
                    {
                        foreach (CatalogEntryDto.SalePriceRow row in catalogEntryDto.SalePrice.Rows)
                        {
                            CatalogEntryDto.SalePriceRow newRow = newCatalogEntryDto.SalePrice.NewSalePriceRow();
                            newRow.ItemArray = row.ItemArray;
                            newRow.ItemCode  = newCatalogEntryDto.CatalogEntry[0].Code;
                            newCatalogEntryDto.SalePrice.Rows.Add(newRow);
                            //newCatalogEntryDto.SalePrice.ImportRow(row);
                            //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].ItemCode = newCatalogEntryDto.CatalogEntry[0].Code;
                            //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].SetAdded();
                        }
                    }

                    if (catalogEntryDto.Inventory.Count > 0)
                    {
                        foreach (CatalogEntryDto.InventoryRow row in catalogEntryDto.Inventory.Rows)
                        {
                            newCatalogEntryDto.Inventory.ImportRow(row);
                            newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SetAdded();
                            newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SkuId = newCatalogEntryDto.CatalogEntry[0].Code;
                        }
                    }

                    if (newCatalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(newCatalogEntryDto);
                    }

                    if (newCatalogEntryDto.CatalogEntry.Count > 0)
                    {
                        CatalogEntryDto.CatalogEntryRow entry = newCatalogEntryDto.CatalogEntry[0];
                        int newCatalogEntryId = entry.CatalogEntryId;
                        int metaClassId       = entry.MetaClassId;

                        // load list of MetaFields for MetaClass
                        MetaClass           metaClass  = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId);
                        MetaFieldCollection metaFields = metaClass.MetaFields;

                        // cycle through each language and get meta objects
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                        string[] languages = GetCatalogLanguages(catalogId);
                        if (languages != null)
                        {
                            foreach (string language in languages)
                            {
                                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                                CatalogContext.MetaDataContext.Language            = language;

                                MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogEntryDto.CatalogEntry[0].CatalogEntryId, metaClassId);

                                MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogEntryId, metaClassId, FrameworkContext.Current.Profile.UserName);

                                foreach (MetaField metaField in metaFields)
                                {
                                    // skip system MetaFields
                                    if (!metaField.IsUser)
                                    {
                                        continue;
                                    }

                                    switch (metaField.DataType)
                                    {
                                    case MetaDataType.File:
                                    case MetaDataType.Image:
                                    case MetaDataType.ImageFile:
                                        MetaFile metaFile = (MetaFile)metaObject[metaField];
                                        if (metaFile != null)
                                        {
                                            newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer);
                                        }
                                        break;

                                    default:
                                        if (metaObject[metaField] != null)
                                        {
                                            newMetaObject[metaField] = metaObject[metaField];
                                        }
                                        break;
                                    }
                                }
                                newMetaObject.AcceptChanges(CatalogContext.MetaDataContext);
                            }
                        }
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;

                        CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto();

                        foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows)
                        {
                            if (row.ParentEntryId == catalogEntryId)
                            {
                                newCatalogRelationDto.CatalogEntryRelation.ImportRow(row);
                                newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].SetAdded();
                                newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].ParentEntryId = newCatalogEntryId;
                            }
                        }

                        if (targetCatalogNodeId > 0)
                        {
                            foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                            {
                                if (row.CatalogEntryId == catalogEntryId)
                                {
                                    newCatalogRelationDto.NodeEntryRelation.ImportRow(row);
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].SetAdded();
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogId      = targetCatalogId;
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogNodeId  = targetCatalogNodeId;
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogEntryId = newCatalogEntryId;
                                }
                            }
                        }

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

                        CatalogAssociationDto newCatalogAssociationDto = new CatalogAssociationDto();

                        foreach (CatalogAssociationDto.CatalogAssociationRow row in catalogAssociationDto.CatalogAssociation.Rows)
                        {
                            newCatalogAssociationDto.CatalogAssociation.ImportRow(row);
                            newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].SetAdded();
                            newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].CatalogEntryId = newCatalogEntryId;
                        }

                        foreach (CatalogAssociationDto.CatalogEntryAssociationRow row in catalogAssociationDto.CatalogEntryAssociation.Rows)
                        {
                            newCatalogAssociationDto.CatalogEntryAssociation.ImportRow(row);
                            newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].SetAdded();
                            //newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].CatalogEntryId = newCatalogEntryId;
                        }

                        if (newCatalogAssociationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogAssociation(newCatalogAssociationDto);
                        }
                    }
                }

                scope.Complete();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            CatalogEntryDto       dto         = null;
            CatalogRelationDto    relation    = null;
            CatalogAssociationDto association = null;

            using (TransactionScope scope = new TransactionScope())
            {
                if (CatalogEntryId > 0)
                {
                    dto         = (CatalogEntryDto)Session[_CatalogEntryDtoString];
                    relation    = (CatalogRelationDto)Session[_CatalogRelationDtoString];
                    association = (CatalogAssociationDto)Session[_CatalogAssociationDtoString];
                }

                if (association == null && CatalogEntryId > 0)
                {
                    association = LoadAssociation();
                }

                if (relation == null && CatalogEntryId > 0)
                {
                    relation = LoadRelation();
                }

                if (dto == null && CatalogEntryId > 0)
                {
                    dto = LoadEntry();
                }

                CreateEmptyDtos(ref dto, ref relation, ref association, true);

                // Put a dictionary key that can be used by other tabs
                IDictionary dic = new ListDictionary();
                dic.Add(_CatalogEntryDtoString, dto);
                dic.Add(_CatalogRelationDtoString, relation);
                dic.Add(_CatalogAssociationDtoString, association);

                // Call tabs save
                ViewControl.SaveChanges(dic);

                // Save modifications
                if (dto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogEntry(dto);
                }

                // get current CatalogEntryId
                int currentCatalogEntryId = this.CatalogEntryId;
                if (dto.CatalogEntry != null && dto.CatalogEntry.Rows.Count > 0)
                {
                    currentCatalogEntryId = dto.CatalogEntry[0].CatalogEntryId;
                }

                // Modify relationship
                CatalogRelationDto.NodeEntryRelationRow relRow = null;

                // Find existing row
                if (relation.NodeEntryRelation.Count > 0)
                {
                    foreach (CatalogRelationDto.NodeEntryRelationRow row in relation.NodeEntryRelation.Rows)
                    {
                        if (row.CatalogEntryId == currentCatalogEntryId && row.CatalogId == ParentCatalogId && row.CatalogNodeId == ParentCatalogNodeId)
                        {
                            relRow = row;
                            break;
                        }
                    }
                }

                // If no existing record found, create a new one
                if (ParentCatalogId > 0 && ParentCatalogNodeId > 0)
                {
                    if (relRow == null)
                    {
                        relRow = relation.NodeEntryRelation.NewNodeEntryRelationRow();
                    }

                    if (ParentCatalogId > 0)
                    {
                        relRow.CatalogId = ParentCatalogId;
                    }

                    if (this.ParentCatalogNodeId > 0)
                    {
                        relRow.CatalogNodeId = this.ParentCatalogNodeId;
                    }

                    relRow.CatalogEntryId = currentCatalogEntryId;

                    // Attach if it is a new row
                    if (relRow.RowState == DataRowState.Detached)
                    {
                        relRow.SortOrder = 0;
                        relation.NodeEntryRelation.Rows.Add(relRow);
                    }
                }

                // Update newly added entry relationships with a parent catalog entry id
                if (relation.CatalogEntryRelation.Rows.Count > 0)
                {
                    foreach (CatalogRelationDto.CatalogEntryRelationRow row in relation.CatalogEntryRelation.Rows)
                    {
                        if (row.RowState == DataRowState.Added && row.ParentEntryId <= 0)
                        {
                            row.ParentEntryId = currentCatalogEntryId;
                        }
                    }
                }

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

                // Update newly added entry relationships with a parent catalog entry id
                if (association.CatalogAssociation.Rows.Count > 0)
                {
                    foreach (CatalogAssociationDto.CatalogAssociationRow row in association.CatalogAssociation.Rows)
                    {
                        if (row.RowState == DataRowState.Added && row.CatalogEntryId <= 0)
                        {
                            row.CatalogEntryId = currentCatalogEntryId;
                        }
                    }
                }

                // Save association modifications
                if (association.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogAssociation(association);
                }

                // Call commit changes
                ViewControl.CommitChanges(dic);

                // Save modifications
                if (dto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogEntry(dto);
                }

                // Save relation modifications
                if (relation.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(relation);
                }

                // Save association modifications
                if (association.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogAssociation(association);
                }

                // Complete transaction
                scope.Complete();

                // we don't need to store Dto in session any more
                Session.Remove(_CatalogEntryDtoString);
                Session.Remove(_CatalogRelationDtoString);
                Session.Remove(_CatalogAssociationDtoString);
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        /// <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);
        }
Beispiel #6
0
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction    = Item[i++];
            object objAssociationName = Item[i++];
            object objParentCode      = Item[i++];
            object objChildCode       = Item[i++];
            object objSortOrder       = Item[i++];
            object objAssociationType = Item[i++];

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string AssociationName;
                if (!String.IsNullOrEmpty((string)objAssociationName))
                {
                    AssociationName = (string)objAssociationName;
                }
                else
                {
                    throw new AbsentValue("Association Name");
                }

                string parentCode;
                if (!String.IsNullOrEmpty((string)objParentCode))
                {
                    parentCode = (string)objParentCode;
                }
                else
                {
                    throw new AbsentValue("Parent Entry Code");
                }

                string childCode;
                if (!String.IsNullOrEmpty((string)objChildCode))
                {
                    childCode = (string)objChildCode;
                }
                else
                {
                    throw new AbsentValue("Child Entry Code");
                }

                bool bIsNew = false;

                //Parent Entry
                CatalogEntryDto.CatalogEntryRow parentEntryRow = null;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(parentCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Associations));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    parentEntryRow = catalogEntryDto.CatalogEntry[0];
                }
                else
                {
                    throw new MDPImportException(String.Format("The Parent Entry with code '{0}' does not exists.", parentCode));
                }

                //Child Entry
                CatalogEntryDto.CatalogEntryRow childEntryRow = null;
                CatalogEntryDto childEntryDto = CatalogEntryManager.GetCatalogEntryDto(childCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                if (childEntryDto.CatalogEntry.Count > 0)
                {
                    childEntryRow = childEntryDto.CatalogEntry[0];
                }
                else
                {
                    throw new MDPImportException(String.Format("The Child Entry with code '{0}' does not exists.", childCode));
                }

                //CatalogAssociation (define CatalogAssociationId)
                int catalogAssociationId = 0;
                CatalogEntryDto.CatalogAssociationRow[] catalogAssociationRows = (CatalogEntryDto.CatalogAssociationRow[])catalogEntryDto.CatalogAssociation.Select(String.Format("AssociationName = '{0}'", AssociationName));
                if (catalogAssociationRows.Length == 0)
                {
                    CatalogEntryDto.CatalogAssociationRow newCatalogAssociationRow = catalogEntryDto.CatalogAssociation.NewCatalogAssociationRow();
                    newCatalogAssociationRow.CatalogEntryId         = parentEntryRow.CatalogEntryId;
                    newCatalogAssociationRow.AssociationName        = AssociationName;
                    newCatalogAssociationRow.AssociationDescription = String.Empty;
                    newCatalogAssociationRow.SortOrder = 0;
                    catalogEntryDto.CatalogAssociation.AddCatalogAssociationRow(newCatalogAssociationRow);

                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);

                    catalogAssociationId = newCatalogAssociationRow.CatalogAssociationId;
                }
                else
                {
                    catalogAssociationId = catalogAssociationRows[0].CatalogAssociationId;
                }

                //catalogEntryAssociationRow
                CatalogAssociationDto catalogAssociationDto = CatalogAssociationManager.GetCatalogAssociationDto(catalogAssociationId);
                CatalogAssociationDto.CatalogAssociationRow catalogAssociationRow = catalogAssociationDto.CatalogAssociation[0];

                CatalogAssociationDto.CatalogEntryAssociationRow catalogEntryAssociationRow = null;

                CatalogAssociationDto.CatalogEntryAssociationRow[] catalogEntryAssociationRows = (CatalogAssociationDto.CatalogEntryAssociationRow[])catalogAssociationDto.CatalogEntryAssociation.Select(String.Format("CatalogEntryId = {0}", childEntryRow.CatalogEntryId));
                if (catalogEntryAssociationRows.Length == 0)
                {
                    if (sysRowAction == RowAction.Update)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode));
                    }

                    if (sysRowAction == RowAction.Delete)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode));
                    }

                    catalogEntryAssociationRow = catalogAssociationDto.CatalogEntryAssociation.NewCatalogEntryAssociationRow();
                    catalogEntryAssociationRow.CatalogAssociationId = catalogAssociationId;
                    catalogEntryAssociationRow.CatalogEntryId       = childEntryRow.CatalogEntryId;
                    catalogEntryAssociationRow.SortOrder            = 0;
                    if (catalogAssociationDto.AssociationType.Count > 0)
                    {
                        catalogEntryAssociationRow.AssociationTypeId = catalogAssociationDto.AssociationType[0].AssociationTypeId;
                    }

                    bIsNew = true;
                }
                else
                {
                    if (sysRowAction == RowAction.Insert)
                    {
                        throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' already exists.", AssociationName, parentCode, childCode));
                    }

                    catalogEntryAssociationRow = catalogEntryAssociationRows[0];

                    if (sysRowAction == RowAction.Delete)
                    {
                        catalogEntryAssociationRow.Delete();
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                        return(0);
                    }
                }

                if (objSortOrder != null)
                {
                    catalogEntryAssociationRow.SortOrder = (int)objSortOrder;
                }

                if (objAssociationType != null)
                {
                    string associationType = (string)objAssociationType;
                    if (!catalogEntryAssociationRow.AssociationTypeId.Equals(associationType))
                    {
                        CatalogAssociationDto.AssociationTypeRow[] associationTypeRows = (CatalogAssociationDto.AssociationTypeRow[])catalogAssociationDto.AssociationType.Select(String.Format("AssociationTypeId = '{0}'", associationType));
                        if (associationTypeRows.Length > 0)
                        {
                            catalogEntryAssociationRow.AssociationTypeId = associationTypeRows[0].AssociationTypeId;
                        }
                    }
                }

                if (bIsNew)
                {
                    catalogAssociationDto.CatalogEntryAssociation.AddCatalogEntryAssociationRow(catalogEntryAssociationRow);
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogAssociationDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(1);
        }
Beispiel #7
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);
                }
            }
        }