/// <summary> /// Moves 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 MoveNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId) { if (catalogId != targetCatalogId) { CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId); if (catalogEntryDto.CatalogEntry.Count > 0) { catalogEntryDto.CatalogEntry[0].CatalogId = targetCatalogId; CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); } } bool addNewRow = false; if (catalogId != targetCatalogId || catalogNodeId != targetCatalogNodeId) { if (catalogNodeId > 0) { CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); if (catalogRelationDto.NodeEntryRelation.Count > 0) { if (targetCatalogNodeId > 0) { catalogRelationDto.NodeEntryRelation[0].CatalogId = targetCatalogId; catalogRelationDto.NodeEntryRelation[0].CatalogNodeId = targetCatalogNodeId; } else { catalogRelationDto.NodeEntryRelation[0].Delete(); } CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } else if (targetCatalogNodeId > 0) { addNewRow = true; } } else if (targetCatalogNodeId > 0) { addNewRow = true; } if (addNewRow) { CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto(); CatalogRelationDto.NodeEntryRelationRow row = newCatalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow(); row.CatalogId = targetCatalogId; row.CatalogNodeId = targetCatalogNodeId; row.CatalogEntryId = catalogEntryId; row.SortOrder = 0; newCatalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row); CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto); } } }
/// <summary> /// Copies 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 CopyNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId) { if (catalogId != targetCatalogId || catalogNodeId != targetCatalogNodeId) { CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(targetCatalogId, targetCatalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); if (catalogRelationDto.NodeEntryRelation.Count == 0) { CatalogRelationDto.NodeEntryRelationRow row = catalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow(); row.CatalogId = targetCatalogId; row.CatalogNodeId = targetCatalogNodeId; row.CatalogEntryId = catalogEntryId; row.SortOrder = 0; catalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row); CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } } }
/// <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); } }
public NodeEntryRelationInfo(CatalogRelationDto.NodeEntryRelationRow relationRow, Dictionary <int, FindDocumentBuilder.CatalogInfo> catalogs, Dictionary <int, FindDocumentBuilder.CatalogNodeInfo> catalogNodes) { this.Catalog = FindDocumentBuilder.CatalogInfo.GetCatalog(relationRow.CatalogId, catalogs); this.Node = FindDocumentBuilder.CatalogNodeInfo.GetCatalogNode(relationRow.CatalogNodeId, catalogs, catalogNodes); }