public bool Import(Guid solutionId, IList <WorkFlow> workFlows) { if (workFlows.NotEmpty()) { foreach (var item in workFlows) { var entity = _workFlowFinder.FindById(item.WorkFlowId); if (entity != null) { entity.Description = item.Description; entity.Name = item.Name; entity.StateCode = item.StateCode; _workFlowUpdater.Update(entity); //steps if (item.Category == 1) { _workFlowStepService.DeleteByParentId(item.WorkFlowId); foreach (var st in item.Steps) { st.WorkFlowId = item.WorkFlowId; } _workFlowStepService.CreateMany(item.Steps); } else if (item.Category == 2) { _processStageService.DeleteByParentId(item.WorkFlowId); foreach (var st in item.Stages) { st.WorkFlowId = item.WorkFlowId; } _processStageService.CreateMany(item.Stages); } } else { item.SolutionId = solutionId; item.ComponentState = 0; item.CreatedBy = _appContext.GetFeature <ICurrentUser>().SystemUserId; item.OrganizationId = _appContext.OrganizationId; _workFlowCreater.Create(item); if (item.Category == 1 && item.Steps.NotEmpty()) { _workFlowStepService.CreateMany(item.Steps); } else if (item.Category == 2 && item.Stages.NotEmpty()) { _processStageService.CreateMany(item.Stages); } } } } return(true); }
public IActionResult CreateWorkFlow([FromBody] CreateWorkFlowModel model) { if (model.StepData.IsEmpty()) { ModelState.AddModelError("", T["workflow_step_empty"]); } if (ModelState.IsValid) { List <WorkFlowStep> steps = new List <WorkFlowStep>(); steps = steps.DeserializeFromJson(model.StepData.UrlDecode()); if (steps.IsEmpty()) { ModelState.AddModelError("", T["workflow_step_empty"]); } if (ModelState.IsValid) { var entity = new WorkFlow(); model.CopyTo(entity); entity.WorkFlowId = Guid.NewGuid(); entity.CreatedBy = CurrentUser.SystemUserId; entity.CreatedOn = DateTime.Now; entity.StateCode = RecordState.Enabled; entity.SolutionId = SolutionId.Value; entity.Category = 1; foreach (var item in steps) { item.Conditions = item.Conditions.UrlDecode(); item.WorkFlowId = entity.WorkFlowId; } entity.Steps = steps; _workFlowCreater.Create(entity); _workFlowStepService.CreateMany(steps); return(CreateSuccess(new { id = entity.WorkFlowId })); } } return(CreateFailure(GetModelErrors())); }