public void Initialize(ISupportStates supportStates) { if (supportStates == null) throw new ArgumentNullException("supportStates"); Model = supportStates; AvailableStates.Clear(); var availableStates = supportStates.GetNextAvailableStates(); if (availableStates != null) foreach (var state in availableStates) AvailableStates.Add(new StateInfoViewModel(this, state)); var currentStateValue = supportStates.CurrentState; var currentState = currentStateValue == null ? supportStates.StateManager.States.FirstOrDefault() : supportStates.StateManager.States.FirstOrDefault(s => s.Id == currentStateValue); CurrentState = new StateInfoViewModel(this, currentState); NextState = null; }
public new static bool CanMove(ISupportStates item, IStateConnector connector) { return StateManager.CanMove(item, connector); }
/// <summary> /// The get next available states with person field. /// </summary> /// <param name="item">The item.</param> /// <param name="personFieldId">The person field id.</param> /// <param name="fieldName">The field name.</param> /// <returns>The <see> /// <cref>IState[]</cref> /// </see> /// .</returns> public IState[] GetNextAvailableStatesWithPersonField(ISupportStates item, int personFieldId, string fieldName) { return GetNextAvailableStates(item); }
/// <summary> /// The can move. /// </summary> /// <param name="item">The item.</param> /// <param name="connector">The connector.</param> /// <returns>The <see cref="bool" />.</returns> protected static bool CanMove(ISupportStates item, IStateConnector connector) { var editableItem = item as IEditableRoot; if (editableItem == null) return false; var user = Csla.ApplicationContext.User; if (!user.Identity.IsAuthenticated) return false; var identity = user.Identity as IMQ1Identity; if (identity == null) return false; if (identity.IsAdmin) return true; var personIds = identity.PersonIds; if (personIds == null) { personIds = new Dictionary<string, int>(); personIds[Constants.BasePersonProcessName] = identity.PersonId; } // Find exact match. if (connector != null) { var config = connector.SecurityConfigurations.FirstOrDefault( c => c.BusinessUnitId == identity.BusinessUnitId && identity.RolesId.Contains(c.RoleId) && IsPersonFieldMatch(editableItem, c, personIds)); if (config != null) return config.CanMove; // Find config with 2 matches. config = connector.SecurityConfigurations.FirstOrDefault( c => (c.BusinessUnitId == identity.BusinessUnitId && identity.RolesId.Contains(c.RoleId) && c.PersonFieldName == Constants.AllPersonFieldsSystemName) || (c.BusinessUnitId == identity.BusinessUnitId && c.RoleId < 0 && IsPersonFieldMatch(editableItem, c, personIds)) || (c.BusinessUnitId < 0 && identity.RolesId.Contains(c.RoleId) && IsPersonFieldMatch(editableItem, c, personIds))); if (config != null) return config.CanMove; // Find config with 1 match. config = connector.SecurityConfigurations.FirstOrDefault( c => (c.BusinessUnitId == identity.BusinessUnitId && c.RoleId < 0 && c.PersonFieldName == Constants.AllPersonFieldsSystemName) || (c.BusinessUnitId < 0 && identity.RolesId.Contains(c.RoleId) && c.PersonFieldName == Constants.AllPersonFieldsSystemName) || (c.BusinessUnitId < 0 && c.RoleId < 0 && IsPersonFieldMatch(editableItem, c, personIds))); if (config != null) return config.CanMove; // Find any match. config = connector.SecurityConfigurations.FirstOrDefault( c => c.BusinessUnitId < 0 && c.RoleId < 0 && c.PersonFieldName == Constants.AllPersonFieldsSystemName); if (config != null) return config.CanMove; } return false; }
/// <summary> /// The get next available states. /// </summary> /// <param name="item">The item.</param> /// <returns>The <see> /// <cref>IState[]</cref> /// </see> /// .</returns> public IState[] GetNextAvailableStates(ISupportStates item) { var currentState = States.FirstOrDefault(s => s.Id == item.CurrentState) ?? States.FirstOrDefault(); Debug.Assert(currentState != null); //ignore the decision nodes return currentState.Connectors.Where(c => CanMove(item, c)).Select(c => c.ConnectedTo).GroupBy(state => state.Guid).Select(grp => grp.First()).ToArray(); }