/// <summary> /// Replaces mandatory relation "to" and resets relation interface /// </summary> /// <param name="toSystemUsage">Replacement system usage</param> public Result <SystemRelation, OperationError> SetRelationTo(ItSystemUsage toSystemUsage) { if (toSystemUsage == null) { throw new ArgumentNullException(nameof(toSystemUsage)); } if (FromSystemUsage.Id == toSystemUsage.Id) { return(new OperationError("'From' cannot equal 'To'", OperationFailure.BadInput)); } //Both ends of the relation must be in same organization if (!CheckSameOrganizationConstraint <ItSystemUsage>(toSystemUsage).GetValueOrFallback(false)) { return(new OperationError("Attempt to create relation to it-system in a different organization", OperationFailure.BadInput)); } ToSystemUsage.Track(); ToSystemUsage = toSystemUsage; RelationInterface.Track(); RelationInterface = RelationInterface .FromNullable() .Select(relationInterface => ToSystemUsage.GetExposedInterface(relationInterface.Id).HasValue) .GetValueOrFallback(false) ? RelationInterface : null; return(this); }
/// <summary> /// Replace relation interface /// </summary> /// <param name="relationInterface">Replacement interface to be used on the relation. None is allowed</param> public Result <SystemRelation, OperationError> SetRelationInterface(Maybe <ItInterface> relationInterface) { if (ToSystemUsage == null) { throw new InvalidOperationException("Cannot set interface to unknown 'To' system"); } if (relationInterface.HasValue) { if (!ToSystemUsage.HasExposedInterface(relationInterface.Value.Id)) { return(new OperationError("Cannot set interface which is not exposed by the 'to' system", OperationFailure.BadInput)); } } RelationInterface.Track(); RelationInterface = relationInterface.GetValueOrDefault(); return(this); }