/// <summary> /// Deletes a <see cref="BinaryRelationship" /> for the selected pair of thing /// </summary> /// <param name="direction">The direction of the relationship to delete</param> /// <returns>The task</returns> private Task DeleteRelationship(RelationshipDirectionKind direction) { if (!(this.SelectedCell is MatrixCellViewModel vm)) { return(Task.FromResult(0)); } var iterationClone = this.iteration.Clone(false); var context = TransactionContextResolver.ResolveContext(iterationClone); var transaction = new ThingTransaction(context, iterationClone); foreach (var binaryRelationship in vm.Relationships) { var clone = binaryRelationship.Clone(false); if (vm.RelationshipDirection != RelationshipDirectionKind.BiDirectional || direction == RelationshipDirectionKind.BiDirectional) { // delete every relationship transaction.Delete(clone); } else if (direction == RelationshipDirectionKind.RowThingToColumnThing && vm.SourceY.Iid == binaryRelationship.Source.Iid) { transaction.Delete(clone); } else if (direction == RelationshipDirectionKind.ColumnThingToRowThing && vm.SourceX.Iid == binaryRelationship.Source.Iid) { transaction.Delete(clone); } } return(this.session.Write(transaction.FinalizeTransaction())); }
/// <summary> /// Creates a <see cref="BinaryRelationship" /> for the selected cell /// </summary> /// <param name="direction">The direction fo the relationship to create</param> /// <returns>The task</returns> private Task CreateRelationship(RelationshipDirectionKind direction) { var vm = this.SelectedCell as MatrixCellViewModel; if (vm == null) { return(Task.FromResult(0)); } var relationship = new BinaryRelationship(Guid.NewGuid(), null, null) { Owner = this.session.OpenIterations[this.iteration].Item1 }; relationship.Category.Add(vm.Rule.RelationshipCategory); relationship.Source = direction == RelationshipDirectionKind.RowThingToColumnThing ? vm.SourceY : vm.SourceX; relationship.Target = direction == RelationshipDirectionKind.RowThingToColumnThing ? vm.SourceX : vm.SourceY; var iterationClone = this.iteration.Clone(false); iterationClone.Relationship.Add(relationship); var context = TransactionContextResolver.ResolveContext(relationship); var transaction = new ThingTransaction(context, iterationClone); transaction.Create(relationship, iterationClone); return(this.session.Write(transaction.FinalizeTransaction())); }