Esempio n. 1
0
        //[ValidateAntiForgeryToken]
        public IActionResult EditWorkFlow([FromBody] EditWorkFlowModel model)
        {
            if (model.StepData.IsEmpty())
            {
                ModelState.AddModelError("", T["workflow_step_empty"]);
            }
            if (ModelState.IsValid)
            {
                model.StepData = model.StepData.UrlDecode();
                List <WorkFlowStep> steps = new List <WorkFlowStep>();
                steps = steps.DeserializeFromJson(model.StepData);
                if (steps.IsEmpty())
                {
                    ModelState.AddModelError("", T["workflow_step_empty"]);
                }
                if (ModelState.IsValid)
                {
                    var entity = _workFlowFinder.FindById(model.WorkFlowId);
                    model.EntityId = entity.EntityId;
                    model.CopyTo(entity);

                    _workFlowUpdater.Update(entity);
                    //steps
                    var orginalSteps = _workFlowStepService.Query(n => n.Where(f => f.WorkFlowId == model.WorkFlowId).Sort(s => s.SortAscending(f => f.StepOrder)));
                    foreach (var item in steps)
                    {
                        item.Conditions = item.Conditions.UrlDecode();
                        var old = orginalSteps.Find(n => n.WorkFlowStepId == item.WorkFlowStepId);
                        if (old == null)
                        {
                            item.WorkFlowId = entity.WorkFlowId;
                            _workFlowStepService.Create(item);
                        }
                        else
                        {
                            _workFlowStepService.Update(item);
                            orginalSteps.Remove(old);
                        }
                    }
                    if (orginalSteps.NotEmpty())
                    {
                        var lostid = orginalSteps.Select(n => n.WorkFlowStepId).ToArray();
                        _workFlowStepService.DeleteById(lostid);
                    }

                    return(UpdateSuccess());
                }
            }
            return(JError(GetModelErrors()));
        }
Esempio n. 2
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);
 }