///-------------------------------------------------------------------------------- /// <summary>This method is used to copy/paste a new item.</summary> /// /// <param name="copyItem">The item to copy/paste.</param> /// <param name="savePaste">Flag to determine whether to save the results of the paste.</param> ///-------------------------------------------------------------------------------- public RelationshipPropertyViewModel PasteRelationshipProperty(RelationshipPropertyViewModel copyItem, bool savePaste = true) { RelationshipProperty newItem = new RelationshipProperty(); newItem.ReverseInstance = new RelationshipProperty(); newItem.TransformDataFromObject(copyItem.RelationshipProperty, null, false); newItem.RelationshipPropertyID = Guid.NewGuid(); newItem.IsAutoUpdated = false; // try to find Property by existing id first, second by old id, finally by name newItem.Property = Relationship.Entity.PropertyList.FindByID((Guid)copyItem.RelationshipProperty.PropertyID); if (newItem.Property == null && Solution.PasteNewGuids[copyItem.RelationshipProperty.PropertyID.ToString()] is Guid) { newItem.Property = Relationship.Entity.PropertyList.FindByID((Guid)Solution.PasteNewGuids[copyItem.RelationshipProperty.PropertyID.ToString()]); } if (newItem.Property == null) { newItem.Property = Relationship.Entity.PropertyList.Find("Name", copyItem.RelationshipProperty.PropertyName); } if (newItem.Property == null) { newItem.OldPropertyID = newItem.PropertyID; newItem.PropertyID = Guid.Empty; } // try to find Property by existing id first, second by old id, finally by name newItem.ReferencedProperty = Relationship.Entity.PropertyList.FindByID((Guid)copyItem.RelationshipProperty.ReferencedPropertyID); if (Relationship.ReferencedEntity == null) { Relationship.ReferencedEntity = Solution.EntityList.FindByID(Relationship.ReferencedEntityID); } if (Relationship.ReferencedEntity == null && copyItem.RelationshipProperty.Relationship.ReferencedEntity != null) { Feature feature = Solution.FeatureList.Find(f => f.FeatureName == copyItem.RelationshipProperty.Relationship.ReferencedEntity.FeatureName); if (feature != null) { Relationship.ReferencedEntity = feature.EntityList.Find(e => e.EntityName == copyItem.RelationshipProperty.Relationship.ReferencedEntity.EntityName); } else { Relationship.ReferencedEntity = Solution.EntityList.Find(e => e.EntityName == copyItem.RelationshipProperty.Relationship.ReferencedEntity.EntityName); } } if (Relationship.ReferencedEntity != null) { if (newItem.ReferencedProperty == null && Solution.PasteNewGuids[copyItem.RelationshipProperty.ReferencedPropertyID.ToString()] is Guid) { newItem.ReferencedProperty = Relationship.ReferencedEntity.PropertyList.FindByID((Guid)Solution.PasteNewGuids[copyItem.RelationshipProperty.ReferencedPropertyID.ToString()]); } if (newItem.ReferencedProperty == null) { newItem.ReferencedProperty = Relationship.ReferencedEntity.PropertyList.Find("Name", copyItem.RelationshipProperty.ReferencedPropertyName); } if (newItem.ReferencedProperty == null && copyItem.RelationshipProperty.ReferencedProperty != null) { newItem.ReferencedProperty = Relationship.ReferencedEntity.PropertyList.Find(p => p.PropertyName == copyItem.RelationshipProperty.ReferencedProperty.PropertyName); } } if (newItem.ReferencedProperty == null) { newItem.OldReferencedPropertyID = newItem.ReferencedPropertyID; newItem.ReferencedPropertyID = Guid.Empty; } newItem.Relationship = Relationship; newItem.Solution = Solution; RelationshipPropertyViewModel newView = new RelationshipPropertyViewModel(newItem, Solution); newView.ResetModified(true); AddRelationshipProperty(newView); if (savePaste == true) { Solution.RelationshipPropertyList.Add(newItem); Relationship.RelationshipPropertyList.Add(newItem); newView.OnUpdated(this, null); Solution.ResetModified(true); } return(newView); }
///-------------------------------------------------------------------------------- /// <summary>This method updates the view model data and sends update command back /// to the solution builder.</summary> ///-------------------------------------------------------------------------------- protected override void OnUpdate() { // set up reverse engineering instance if not present if (RelationshipProperty.ReverseInstance == null && RelationshipProperty.IsAutoUpdated == true) { RelationshipProperty.ReverseInstance = new RelationshipProperty(); RelationshipProperty.ReverseInstance.TransformDataFromObject(RelationshipProperty, null, false); // perform the update of EditRelationshipProperty back to RelationshipProperty RelationshipProperty.TransformDataFromObject(EditRelationshipProperty, null, false); RelationshipProperty.IsAutoUpdated = false; } else if (RelationshipProperty.ReverseInstance != null) { EditRelationshipProperty.ResetModified(RelationshipProperty.ReverseInstance.IsModified); if (EditRelationshipProperty.Equals(RelationshipProperty.ReverseInstance)) { // perform the update of EditRelationshipProperty back to RelationshipProperty RelationshipProperty.TransformDataFromObject(EditRelationshipProperty, null, false); RelationshipProperty.IsAutoUpdated = true; } else { // perform the update of EditRelationshipProperty back to RelationshipProperty RelationshipProperty.TransformDataFromObject(EditRelationshipProperty, null, false); RelationshipProperty.IsAutoUpdated = false; } } else { // perform the update of EditRelationshipProperty back to RelationshipProperty RelationshipProperty.TransformDataFromObject(EditRelationshipProperty, null, false); RelationshipProperty.IsAutoUpdated = false; } RelationshipProperty.ForwardInstance = null; if (PropertyIDCustomized || ReferencedPropertyIDCustomized || OrderCustomized || DescriptionCustomized || TagsCustomized) { RelationshipProperty.ForwardInstance = new RelationshipProperty(); RelationshipProperty.ForwardInstance.RelationshipPropertyID = EditRelationshipProperty.RelationshipPropertyID; RelationshipProperty.SpecSourceName = RelationshipProperty.DefaultSourceName; if (PropertyIDCustomized) { RelationshipProperty.ForwardInstance.PropertyID = EditRelationshipProperty.PropertyID; } if (ReferencedPropertyIDCustomized) { RelationshipProperty.ForwardInstance.ReferencedPropertyID = EditRelationshipProperty.ReferencedPropertyID; } if (OrderCustomized) { RelationshipProperty.ForwardInstance.Order = EditRelationshipProperty.Order; } if (DescriptionCustomized) { RelationshipProperty.ForwardInstance.Description = EditRelationshipProperty.Description; } if (TagsCustomized) { RelationshipProperty.ForwardInstance.Tags = EditRelationshipProperty.Tags; } } EditRelationshipProperty.ResetModified(false); OnUpdated(this, null); // send update back to solution builder SendEditRelationshipPropertyPerformed(); }