public void ManageTransition <T, C, L>(IStateChange <T, C, L> change, C newState, L model) where T : class, IStateChangeEntityBase <C> where C : Enum where L : class { CheckCorrectOverloadForTasks(change); BasicWorkFlowManage(change, newState); change.IsValid(model); change.StateAction(model); ChangeStatus(change, newState); }
/// <summary> /// !!! Calls SaveChanges on <see cref="IRLSRepository{Entity, ACLEntity}"/> /// </summary> /// <typeparam name="T">Entity</typeparam> /// <typeparam name="C">State</typeparam> /// <typeparam name="K">Task entity</typeparam> /// <param name="change"></param> public K[] ManageTransition <T, C, K, AclEntity>(IStateChange <T, C> change, C newState, IRLSRepository <K, AclEntity> RlsRepository) where T : class, IStateChangeEntityBase <C> where C : Enum where K : TaskEntity, new() where AclEntity : class, IACLEntity, new() { CheckCorrectOverloadForViewModel(change); BasicWorkFlowManage(change, newState); change.IsValid(); change.StateAction(); var tasks = TaskCreationManage <T, C, K, AclEntity>(change, RlsRepository); ChangeStatus(change, newState); return(tasks); }
public K[] ManageTransition <T, C, K, L, AclEntity>(IStateChange <T, C, L> change, C newState, L model, IRLSRepository <K, AclEntity> RlsRepository) where T : class, IStateChangeEntityBase <C> where C : Enum where K : TaskEntity, new() where L : class where AclEntity : class, IACLEntity, new() { BasicWorkFlowManage(change, newState); change.IsValid(model); change.StateAction(model); var tasks = TaskCreationManage <T, C, K, AclEntity>(change, RlsRepository); ChangeStatus(change, newState); return(tasks); }
private void BasicWorkFlowManage <T, C>(IStateChange <T, C> change, C newState) where T : class, IStateChangeEntityBase <C> where C : Enum { void HasSufficentPermission() { var changeConfiguration = change.GetConfiguration(); if (changeConfiguration != null && changeConfiguration.HasPermissionToFullfillChange != null && changeConfiguration.HasPermissionToFullfillChange.Length > 0) { if (changeConfiguration.HasPermissionToFullfillChange.Any(x => CurrentUserGoups.Contains(x.Id))) { return; } else { throw new StateTransitionException($"User has no permission to perform this transition. Change type: {change.GetType().Name}"); } } else { throw new Exception($"Invalid {nameof(StateChangeConfiguration)}. Override {nameof(change.GetConfiguration)} properly!"); } } void StateTransitionValid() { var changeConfiguration = change.GetConfiguration(); if (changeConfiguration == null) { throw new Exception($"Invalid {nameof(StateChangeConfiguration)} object!"); } if (changeConfiguration.AllowedStartStates != null && changeConfiguration.AllowedStartStates.Length > 0) { if (!changeConfiguration.AllowedStartStates.Contains(change.Entity.CurrentState)) { throw new StateTransitionException($"Tried transition from {change.Entity.CurrentState} to {newState}, which is disallowed! " + $"(possible state change outside of {nameof(StateManagger)}"); } } if (changeConfiguration.AllowedEndStates != null && changeConfiguration.AllowedEndStates.Length > 0) { if (!changeConfiguration.AllowedEndStates.Contains(newState)) { throw new StateTransitionException($"Tried transition to '{newState}', which is disallowed end state!"); } } } void TestChangeRule() { change.IsValid(); } HasSufficentPermission(); StateTransitionValid(); TestChangeRule(); }