Example #1
0
 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);
 }
Example #2
0
        //[ValidateAntiForgeryToken]
        public IActionResult CreateBusinessFlow([FromBody] CreateWorkFlowModel model)
        {
            if (model.StepData.IsEmpty())
            {
                ModelState.AddModelError("", T["workflow_step_empty"]);
            }
            List <ProcessStage> steps = new List <ProcessStage>();

            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.Category   = 2;
                entity.CreatedBy  = CurrentUser.SystemUserId;
                entity.CreatedOn  = DateTime.Now;
                entity.StateCode  = Core.RecordState.Enabled;
                entity.SolutionId = SolutionId.Value;
                foreach (var item in steps)
                {
                    item.ProcessStageId = Guid.NewGuid();
                    item.WorkFlowId     = entity.WorkFlowId;
                }

                _workFlowCreater.Create(entity);
                _processStageService.CreateMany(steps);
                return(CreateSuccess(new { id = entity.WorkFlowId }));
            }
            return(CreateFailure(GetModelErrors()));
        }