public async Task <FlowResult <FlowTransition> > CreateFlowTransitionAsync(InitFlowTransitionModel model) { var set = StateManager.GetFlowSet <FlowTransition>(); var stateSet = StateManager.GetFlowSet <FlowState>(); var source = await stateSet.GetByIdAsync(model.SourceId); if (source == null) { return(FlowResult <FlowTransition> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(source)))); } var destination = await stateSet.GetByIdAsync(model.DestinationId); if (destination == null) { return(FlowResult <FlowTransition> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(destination)))); } var entity = FlowEntity.InitializeType(new FlowTransition() { Name = model.Name, Title = model.Title, SourceId = source.Id, DestinationId = destination.Id, TransitionType = model.TransitionType, TypeId = source.TypeId, }); var result = await set.CreateAsync(entity); return(FlowResult <FlowTransition> .Successful(result)); }
public async Task <FlowResult <FlowState> > CreateFlowStateAsync(InitFlowStateModel model) { var set = StateManager.GetFlowSet <FlowState>(); var typeSet = StateManager.GetFlowSet <FlowType>(); var type = await typeSet.GetByIdAsync(model.TypeId); if (type == null) { return(FlowResult <FlowState> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(type)))); } var entity = FlowEntity.InitializeType(new FlowState() { Name = model.Name, Title = model.Title, StateType = (byte)model.StateType, TypeId = type.Id, Tag = model.Tag, }); var result = await set.CreateAsync(entity); return(FlowResult <FlowState> .Successful(result)); }
public async Task <FlowResult <FlowInstance> > CreateFlowInstanceAsync(InitFlowModel model) { var set = StateManager.GetFlowSet <FlowInstance>(); var typeSet = StateManager.GetFlowSet <FlowType>(); var type = await typeSet.GetByIdAsync(model.TypeId); if (type == null) { return(FlowResult <FlowInstance> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(type)))); } var entity = FlowEntity.InitializeType(new FlowInstance() { Title = model.Title, Payload = model.Payload, TypeId = type.Id, InitializerId = model.InitializerId, AccessPhrase = model.AccessPhrase, }); var result = await set.CreateAsync(entity); return(FlowResult <FlowInstance> .Successful(result)); }
public async Task <FlowResult <FlowType> > CreateFlowTypeAsync(InitFlowTypeModel initModel) { var set = StateManager.GetFlowSet <FlowType>(); var entity = FlowEntity.InitializeType(new FlowType() { EntityType = initModel.EntityType.FullName, EntityPayloadType = initModel.EntityPayloadType.FullName, Name = initModel.Name, }); var resultTask = await set.CreateAsync(entity); return(FlowResult <FlowType> .Successful(resultTask)); }
public async Task <FlowResult <FlowStep> > CreateFlowStepAsync(MoveModel model) { var set = StateManager.GetFlowSet <FlowStep>(); var instanceSet = StateManager.GetFlowSet <FlowInstance>(); var transitionSet = StateManager.GetFlowSet <FlowTransition>(); var stateSet = StateManager.GetFlowSet <FlowState>(); var instance = await instanceSet.GetByIdAsync(model.InstanceId); if (instance == null) { return(FlowResult <FlowStep> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(instance)))); } var transition = await transitionSet.GetByIdAsync(model.TransitionId); if (transition == null) { return(FlowResult <FlowStep> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(transition)))); } var state = await stateSet.GetByIdAsync(transition.DestinationId); if (state == null) { return(FlowResult <FlowStep> .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(state)))); } var entity = FlowEntity.InitializeType(new FlowStep() { InstanceId = instance.Id, IsCurrent = true, TransitionId = transition.Id, Payload = model.Payload, Comment = model.Comment, CurrentStateName = state.Name, CurrentStateTitle = state.Title, CurrentStateType = state.StateType, }); var result = await set.CreateAsync(entity); return(FlowResult <FlowStep> .Successful(result)); }