/// <summary> /// Called when [deleting]. /// </summary> protected override void OnDeleting() { base.OnDeleting(); CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(PrimaryKeyId.ToString()); if (catalogRelationDto.CatalogItemAsset.Count > 0) { for (int i = 0; i < catalogRelationDto.CatalogItemAsset.Count; i++) { catalogRelationDto.CatalogItemAsset[i].Delete(); } if (catalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } } // Clean Up BlobStorage BlobStorageProvider provider = BlobStorage.Providers[BlobStorageProvider]; if (provider != null) { BlobInfo blobInfo = provider.GetInfo((Guid)BlobUid); if (blobInfo != null) { provider.ReleaseStream(blobInfo); } } }
/// <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> /// 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> /// Processes the delete command. /// </summary> /// <param name="items">The items.</param> /// <param name="parentCatalogId">The parent catalog id.</param> /// <param name="parentCatalogNodeId">The parent catalog node id.</param> void ProcessDeleteCommand(string[] items, int parentCatalogId, int parentCatalogNodeId) { for (int i = 0; i < items.Length; i++) { string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]); if (keys != null) { int id = Int32.Parse(keys[0]); string type = keys[1]; if (id > 0) { if (String.Compare(type, "Node", true) == 0 || String.Compare(type, "LevelUp", true) == 0) { CatalogNodeDto catalogNodeDto = CatalogContext.Current.GetCatalogNodesDto(parentCatalogId); CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogNode | CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); DeleteNodeRecursive(id, parentCatalogId, ref catalogNodeDto, ref catalogRelationDto); if (catalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } if (catalogNodeDto.HasChanges()) { CatalogContext.Current.SaveCatalogNode(catalogNodeDto); } } else // entry { DeleteEntryRecursive(id, parentCatalogId, parentCatalogNodeId); } } } } }
/// <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(); } }
/// <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); } }
/// <summary> /// Updates static field /// </summary> /// <param name="item">The data item.</param> /// <returns></returns> private void UpdateStaticField(CatalogEntryDto.CatalogEntryRow item) { CatalogEntryDto dto = new CatalogEntryDto(); CatalogEntryDto.VariationRow[] variationRows = null; decimal decimalValue = 0; int intValue = 0; double doubleValue = 0; switch (FieldName) { case "Name": item.Name = tbItem.Text; dto.CatalogEntry.ImportRow(item); break; case "StartDate": item.StartDate = cdpItem.Value; dto.CatalogEntry.ImportRow(item); break; case "EndDate": item.EndDate = cdpItem.Value; dto.CatalogEntry.ImportRow(item); break; case "TemplateName": item.TemplateName = ddlItem.SelectedValue; dto.CatalogEntry.ImportRow(item); break; case "Code": if (item.InventoryRow != null) { CatalogEntryDto.InventoryRow inventoryRow = item.InventoryRow; inventoryRow.SkuId = tbItem.Text; dto.Inventory.ImportRow(inventoryRow); } item.Code = tbItem.Text; dto.CatalogEntry.ImportRow(item); break; case "SortOrder": intValue = -1; if (Int32.TryParse(tbItem.Text, out intValue)) { CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(item.CatalogId, CatalogNodeId, item.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); // Update relations foreach (CatalogRelationDto.NodeEntryRelationRow row in relationDto.NodeEntryRelation) { row.SortOrder = intValue; } if (relationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(relationDto); } } break; case "IsActive": item.IsActive = becItem.IsSelected; dto.CatalogEntry.ImportRow(item); break; case "ListPrice": decimalValue = 0; if (Decimal.TryParse(tbItem.Text, out decimalValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0].ListPrice = decimalValue; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } break; case "TrackInventory": variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0].TrackInventory = becItem.IsSelected; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } break; case "MerchantId": if (!String.IsNullOrEmpty(ddlItem.SelectedValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0].MerchantId = new Guid(ddlItem.SelectedValue); dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } break; case "Weight": doubleValue = 0; if (Double.TryParse(tbItem.Text, out doubleValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0].Weight = doubleValue; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } break; case "TaxCategoryId": case "WarehouseId": case "PackageId": if (!String.IsNullOrEmpty(ddlItem.SelectedValue)) { intValue = 0; if (Int32.TryParse(ddlItem.SelectedValue, out intValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0][FieldName] = intValue; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } } break; case "MinQuantity": case "MaxQuantity": decimalValue = 1; if (Decimal.TryParse(tbItem.Text, out decimalValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0][FieldName] = decimalValue; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } break; case "InStockQuantity": case "ReservedQuantity": case "ReorderMinQuantity": case "PreorderQuantity": case "BackorderQuantity": decimalValue = 0; if (Decimal.TryParse(tbItem.Text, out decimalValue)) { if (item.InventoryRow != null) { item.InventoryRow[FieldName] = decimalValue; dto.CatalogEntry.ImportRow(item); dto.Inventory.ImportRow(item.InventoryRow); } } break; case "AllowBackorder": case "AllowPreorder": if (item.InventoryRow != null) { item.InventoryRow[FieldName] = becItem.IsSelected; dto.CatalogEntry.ImportRow(item); dto.Inventory.ImportRow(item.InventoryRow); } break; case "InventoryStatus": if (!String.IsNullOrEmpty(ddlItem.SelectedValue)) { intValue = 0; if (Int32.TryParse(ddlItem.SelectedValue, out intValue)) { if (item.InventoryRow != null) { item.InventoryRow[FieldName] = intValue; dto.CatalogEntry.ImportRow(item); dto.Inventory.ImportRow(item.InventoryRow); } } } break; case "PreorderAvailabilityDate": case "BackorderAvailabilityDate": if (item.InventoryRow != null) { item.InventoryRow[FieldName] = cdpItem.Value; dto.CatalogEntry.ImportRow(item); dto.Inventory.ImportRow(item.InventoryRow); } break; } if (dto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(dto); } }
/// <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); }
protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item) { int i = 0; object objSysRowAction = Item[i++]; object objParentCode = Item[i++]; object objChildCode = Item[i++]; object objQuantity = Item[i++]; object objGroupName = Item[i++]; object objSortOrder = Item[i++]; CatalogRelationDto.CatalogEntryRelationRow catalogEntryRelationRow = null; CatalogRelationDto catalogRelationDto = new CatalogRelationDto(); try { RowAction sysRowAction = RowAction.Default; if (objSysRowAction != null) { sysRowAction = GetRowActionEnum((string)objSysRowAction); } 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; CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(parentCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (catalogEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow entry = catalogEntryDto.CatalogEntry[0]; if (entry.ClassTypeId.Equals(EntryType.Product, StringComparison.OrdinalIgnoreCase) || entry.ClassTypeId.Equals(EntryType.Bundle, StringComparison.OrdinalIgnoreCase) || entry.ClassTypeId.Equals(EntryType.Package, StringComparison.OrdinalIgnoreCase) || entry.ClassTypeId.Equals(EntryType.DynamicPackage, StringComparison.OrdinalIgnoreCase)) { CatalogEntryDto childEntryDto = CatalogEntryManager.GetCatalogEntryDto(childCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (childEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow childEntry = childEntryDto.CatalogEntry[0]; catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(this._CatalogId, 0, entry.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry)); if (catalogRelationDto.CatalogEntryRelation.Count > 0) { DataRow[] drs = catalogRelationDto.CatalogEntryRelation.Select(String.Format("ParentEntryId = {0} AND ChildEntryId = {1}", entry.CatalogEntryId, childEntry.CatalogEntryId)); if (drs.Length > 0) { catalogEntryRelationRow = (CatalogRelationDto.CatalogEntryRelationRow)drs[0]; if (sysRowAction == RowAction.Insert) { throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' already exists.", parentCode, childCode)); } if (sysRowAction == RowAction.Delete) { catalogEntryRelationRow.Delete(); CatalogRelationManager.SaveCatalogRelation(catalogRelationDto); return(0); } } } if (catalogEntryRelationRow == null) { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' does not exists.", parentCode, childCode)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' does not exists.", parentCode, childCode)); } catalogEntryRelationRow = catalogRelationDto.CatalogEntryRelation.NewCatalogEntryRelationRow(); catalogEntryRelationRow.ParentEntryId = entry.CatalogEntryId; catalogEntryRelationRow.ChildEntryId = childEntry.CatalogEntryId; catalogEntryRelationRow.Quantity = 1; catalogEntryRelationRow.GroupName = String.Empty; catalogEntryRelationRow.SortOrder = 0; switch (entry.ClassTypeId) { case EntryType.Product: catalogEntryRelationRow.RelationTypeId = EntryRelationType.ProductVariation; break; case EntryType.Package: catalogEntryRelationRow.RelationTypeId = EntryRelationType.PackageEntry; break; case EntryType.Bundle: case EntryType.DynamicPackage: catalogEntryRelationRow.RelationTypeId = EntryRelationType.BundleEntry; break; } bIsNew = true; } } else { throw new MDPImportException(String.Format("The Child Entry with code '{0}' does not exists.", childCode)); } } else { throw new MDPImportException(String.Format("The Parent Entry with code '{0}' has wrong type ('{1}').", parentCode, entry.ClassTypeId)); } } else { throw new MDPImportException(String.Format("The Parent Entry with code '{0}' does not exists.", parentCode)); } //SalePrice if (objQuantity != null) { catalogEntryRelationRow.Quantity = (decimal)objQuantity; } if (objGroupName != null) { catalogEntryRelationRow.GroupName = (string)objGroupName; } if (objSortOrder != null) { catalogEntryRelationRow.SortOrder = (int)objSortOrder; } if (bIsNew) { catalogRelationDto.CatalogEntryRelation.AddCatalogEntryRelationRow(catalogEntryRelationRow); } using (TransactionScope tx = new TransactionScope()) { // Save modifications if (catalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } tx.Complete(); } } catch (Exception ex) { throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item); } return(catalogEntryRelationRow.ParentEntryId); }
/// <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); } } }