/// <summary> /// Map /// </summary> /// <param name="model"></param> /// <param name="workFlowId"></param> /// <returns></returns> public static Transition Map(AddTransitionViewModel model, Guid?workFlowId) { Arg.NotNull(model, nameof(AddTransitionViewModel)); Arg.NotNull(workFlowId, nameof(Map)); return(new Transition { Name = model.Name, FromStateId = model.FromStateId, ToStateId = model.ToStateId, WorkflowId = workFlowId.GetValueOrDefault() }); }
/// <summary> /// Create transition /// </summary> /// <param name="workFlowId"></param> /// <param name="model"></param> /// <returns></returns> public async Task <ResultModel <Guid> > CreateTransitionAsync([Required] Guid?workFlowId, AddTransitionViewModel model) { Arg.NotNull(model, nameof(AddTransitionViewModel)); var response = new ResultModel <Guid>(); var workflowRequest = await GetWorkFlowByIdAsync(workFlowId); if (!workflowRequest.IsSuccess) { return(workflowRequest.Map <Guid>()); } var workFlow = workflowRequest.Result; var fromState = workFlow.States.FirstOrDefault(x => x.Id.Equals(model.FromStateId)); var toState = workFlow.States.FirstOrDefault(x => x.Id.Equals(model.ToStateId)); if (fromState == null || toState == null) { response.Errors.Add(new ErrorModel(string.Empty, $"Workflow {workFlow.Name} does not have such states")); return(response); } if (IsDuplicateTransition(workFlow, model.FromStateId, model.ToStateId)) { response.Errors.Add(new ErrorModel(nameof(WorkFlowErrorCodes.GRWF_0x101), WorkFlowErrorCodes.GRWF_0x101)); return(response); } if (IsConnectionByItSelf(workFlow, model.FromStateId, model.ToStateId)) { response.Errors.Add(new ErrorModel(nameof(WorkFlowErrorCodes.GRWF_0x100), WorkFlowErrorCodes.GRWF_0x100)); return(response); } var transition = WorkFlowMapper.Map(model, workFlowId); await _workFlowContext.Transitions.AddAsync(transition); var dbRequest = await _workFlowContext.PushAsync(); return(dbRequest.Map(transition.Id)); }
public async Task <JsonResult> CreateTransition([Required] Guid?workFlowId, [Required] AddTransitionViewModel model) { return(!ModelState.IsValid ? Json(new InvalidParametersResultModel <Guid>().AttachModelState(ModelState)) : await JsonAsync(_workFlowCreatorService.CreateTransitionAsync(workFlowId, model))); }