internal Association_AddFromDialog(NewAssociationDialog dialog) { _dialog = dialog; }
internal void AddNewAssociation(EntityTypeShape entityShape) { if ((Partition.GetLocks() & Locks.Add) == Locks.Add) { return; } // If user selected an EntityTypeShape, use corresponding EntityType // else default to first EntityType in the model ViewModelEntityType end1 = null; if (entityShape != null) { end1 = entityShape.ModelElement as ViewModelEntityType; } if (end1 == null) { end1 = ModelElement.EntityTypes[0]; } // Pick something for the second end (defaulting to the next EntityType in the model) ViewModelEntityType end2 = null; var index = ModelElement.EntityTypes.IndexOf(end1) + 1; if (ModelElement.EntityTypes.Count <= index) { index = 0; } end2 = ModelElement.EntityTypes[index]; var modelEnd1Entity = ModelElement.ModelXRef.GetExisting(end1) as Model.Entity.EntityType; var modelEnd2Entity = ModelElement.ModelXRef.GetExisting(end2) as Model.Entity.EntityType; Debug.Assert(modelEnd1Entity != null && modelEnd2Entity != null); var model = modelEnd1Entity.Parent as ConceptualEntityModel; Debug.Assert(model != null); using (var dialog = new NewAssociationDialog(model.EntityTypes(), modelEnd1Entity, modelEnd2Entity)) { if (dialog.ShowDialog() == DialogResult.OK) { try { Store.RuleManager.DisableRule(typeof(Association_AddRule)); using (var t = Store.TransactionManager.BeginTransaction(EntityDesignerResources.Tx_AddAssociation)) { t.Context.Add(EfiTransactionOriginator.TransactionOriginatorDiagramId, DiagramId); ViewModelChangeContext.GetNewOrExistingContext(t).ViewModelChanges.Add(new Association_AddFromDialog(dialog)); t.Commit(); } } finally { Store.RuleManager.EnableRule(typeof(Association_AddRule)); } } } }