/// <summary> /// Removes a <see cref="StatePropertyDefinition"/> from of the <see cref="StateProperties"/> list. /// </summary> /// <param name="stateProperty">The <see cref="StatePropertyDefinition"/> to be removed. Must not be <see langword="null" />.</param> /// <remarks> /// Also deletes all entries from the <see cref="StatefulAccessControlLists"/> list that use only the removed <see cref="StatePropertyDefinition"/> /// as a selection criteria. /// </remarks> /// <exception cref="ArgumentException"> /// The <paramref name="stateProperty"/> does not exist on the <see cref="SecurableClassDefinition"/>. /// </exception> public void RemoveStateProperty(StatePropertyDefinition stateProperty) { ArgumentUtility.CheckNotNull("stateProperty", stateProperty); var statePropertyReference = StatePropertyReferences.SingleOrDefault(r => r.StateProperty == stateProperty); if (statePropertyReference == null) { throw CreateArgumentException( "stateProperty", "The property '{0}' does not exist on the securable class definition.", stateProperty.Name); } statePropertyReference.Delete(); foreach (var acl in StatefulAccessControlLists.ToList()) { var stateCombinationsContainingRemovedStateProperty = acl.StateCombinations.Where(sc => sc.GetStates().Any(sd => sd.StateProperty == stateProperty)).ToList(); foreach (var stateCombination in stateCombinationsContainingRemovedStateProperty) { stateCombination.Delete(); if (!acl.StateCombinations.Any()) { acl.Delete(); } } } RegisterForCommit(); }
protected override void OnDeleting(EventArgs args) { if (StatePropertyReferences.Any()) { throw new InvalidOperationException( string.Format("State property '{0}' cannot be deleted because it is associated with at least one securable class definition.", Name)); } base.OnDeleting(args); //TODO: Rewrite with test _deleteHandler = new DomainObjectDeleteHandler(LocalizedNames); }
/// <summary> /// Adds a <see cref="StatePropertyDefinition"/> to the <see cref="StateProperties"/> list. /// </summary> /// <param name="stateProperty">The <see cref="StatePropertyDefinition"/> to be added. Must not be <see langword="null" />.</param> /// <exception cref="ArgumentException"> /// The <paramref name="stateProperty"/> already exists on the <see cref="SecurableClassDefinition"/>. /// </exception> public void AddStateProperty(StatePropertyDefinition stateProperty) { ArgumentUtility.CheckNotNull("stateProperty", stateProperty); if (StatePropertyReferences.Where(r => r.StateProperty == stateProperty).Any()) { throw CreateArgumentException( "stateProperty", "The property '{0}' has already been added to the securable class definition.", stateProperty.Name); } var reference = StatePropertyReference.NewObject(); reference.StateProperty = stateProperty; StatePropertyReferences.Add(reference); RegisterForCommit(); }
/// <summary> /// Removes a <see cref="StateDefinition"/> from of the <see cref="DefinedStates"/> list. /// </summary> /// <param name="state">The <see cref="StateDefinition"/> to be removed. Must not be <see langword="null" />.</param> /// <remarks> /// Also deletes all <see cref="StatefulAccessControlList"/> objects that use only the removed <see cref="StateDefinition"/> /// as a selection criteria. /// </remarks> /// <exception cref="ArgumentException"> /// The <paramref name="state"/> does not exist on the <see cref="StatePropertyDefinition"/>. /// </exception> public void RemoveState(StateDefinition state) { ArgumentUtility.CheckNotNull("state", state); if (!DefinedStatesInternal.Contains(state.ID)) { throw CreateArgumentException("state", "The state '{0}' does not exist on the property '{1}'.", state.Name, Name); } DefinedStatesInternal.Remove(state); foreach (var acl in StatePropertyReferences.SelectMany(r => r.Class.StatefulAccessControlLists).ToList()) { var stateCombinationsContainingRemovedState = acl.StateCombinations.Where(sc => sc.GetStates().Contains(state)).ToList(); foreach (var stateCombination in stateCombinationsContainingRemovedState) { stateCombination.Delete(); if (!acl.StateCombinations.Any()) { acl.Delete(); } } } }