/// <summary>
        /// it is used by Combo search to get name of entity using text/value field
        /// </summary>
        public VariableModel GetEntityWithKeyValue(string variableName, Dictionary <string, object> dictionary)
        {
            string          whereClause   = string.Empty;
            sysBpmsVariable variable      = new VariableService(base.UnitOfWork).GetInfo(base.EngineSharedModel?.CurrentProcessID, base.EngineSharedModel?.CurrentApplicationPageID, variableName, new string[] { nameof(sysBpmsVariable.DependentVariableDependencies), nameof(sysBpmsVariable.EntityDef) });
            VariableModel   variableModel = null;

            if (variable != null)
            {
                switch ((sysBpmsVariable.e_RelationTypeLU)variable.RelationTypeLU)
                {
                case sysBpmsVariable.e_RelationTypeLU.SqlQuery:
                    variable.WhereClause = string.Join(" and ", dictionary.Select(c => $"{c.Key}='{c.Value}'"));
                    //this set each DataModel's key corresponding to returned columns by query and then set value into it.
                    variableModel = new VariableModel(variableName, new SqlQueryVariableTypeEngine(base.EngineSharedModel, variable, base.EngineSharedModel?.CurrentProcessID, this.ThreadID, this.AdditionalParams, base.UnitOfWork).GetResult(null));
                    break;

                case sysBpmsVariable.e_RelationTypeLU.Entity:
                    //this set each DataModel's key corresponding to returned columns by query and then set value into it.
                    //this method return one DataModel if the _Variable FilterTypeLU is Filtered otherwise it will return list of DataModel.
                    variable.WhereClause = string.Join(" and ", dictionary.Select(c => $"{variable.EntityDef.FormattedTableName}.{c.Key}='{c.Value}'"));
                    variableModel        = new VariableModel(variableName, new EntityVariableTypeEngine(base.EngineSharedModel, variable, base.EngineSharedModel?.CurrentProcessID, this.ThreadID, this.AdditionalParams, base.UnitOfWork).GetResult(null));
                    break;
                }
            }
            return(variableModel);
        }
        /// <summary>
        /// this method add variable dependies to whereclause which have relation with current variable.
        /// </summary>
        /// <param name="queryParams">it would update this parameter.</param>
        private void AddDependencyClause(sysBpmsVariable variable, List <SqlParameter> queryParams, List <SqlParameter> insertColumnParams, ref string whereClause, List <QueryModel> additionalParams, Dictionary <string, DataModel> allSavedEntities = null)
        {
            //add variable dependies where clause which have relation with current variable
            if (variable.DependentVariableDependencies.Any())
            {
                foreach (sysBpmsVariableDependency item in variable.DependentVariableDependencies)
                {
                    object value      = null;
                    var    toVariable = new VariableService(base.UnitOfWork).GetInfo(item.ToVariableID.Value);
                    //set BindTrace to find a field of a entity variable if the variable is entity.
                    string BindTrace = $"{toVariable.Name}{(!string.IsNullOrWhiteSpace(item.ToPropertyName) ? ("." + item.ToPropertyName) : "")}";
                    whereClause += $"{(string.IsNullOrWhiteSpace(whereClause) ? "" : " and ")}{item.DependentPropertyName}=@{BindTrace.Replace(".", "_")}";

                    if (allSavedEntities?.ContainsKey(toVariable.Name) == true && allSavedEntities[toVariable.Name][BindTrace.Split('.').LastOrDefault()] != null)
                    {
                        value = allSavedEntities[toVariable.Name][BindTrace.Split('.').LastOrDefault()];
                    }
                    else
                    {
                        value = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork).GetValueByBinding(BindTrace, base.GetAllQueryModels(additionalParams));
                    }

                    queryParams.Add(new SqlParameter($"@{BindTrace.Replace(".", "_")}", value ?? DBNull.Value));

                    if (insertColumnParams != null)
                    {
                        if (!insertColumnParams.Any(c => c.ParameterName.TrimStart('@') == item.DependentPropertyName))
                        {
                            insertColumnParams.Add(new SqlParameter("@" + item.DependentPropertyName, value ?? DBNull.Value));
                        }
                    }
                }
            }
            whereClause = string.IsNullOrWhiteSpace(whereClause) ? "" : (whereClause.Trim().StartsWith("where") ? whereClause : (" where " + whereClause));
        }
 public List <sysBpmsDocument> GetList(Guid?documentDefId, Guid?VariableId, Guid?documentFolderId)
 {
     if (VariableId.HasValue)
     {
         sysBpmsVariable  variable  = new VariableService(base.UnitOfWork).GetInfo(VariableId.Value);
         sysBpmsEntityDef entityDef = new EntityDefService(base.UnitOfWork).GetInfo(variable.EntityDefID.Value);
         Guid?            entityId  = new EntityDefEngine(base.EngineSharedModel, base.UnitOfWork).GetEntityID(entityDef, variable, base.EngineSharedModel.BaseQueryModel);
         if (entityId.HasValue)
         {
             return(new DocumentService(base.UnitOfWork).GetList(documentDefId, variable.EntityDefID, entityId, "", false, documentFolderId, null));
         }
         else
         {
             return(new List <sysBpmsDocument>());
         }
     }
     else
     {
         if (documentDefId.HasValue || documentFolderId.HasValue)
         {
             return(new DocumentService(base.UnitOfWork).GetList(documentDefId, null, null, "", false, documentFolderId, base.EngineSharedModel.CurrentThreadID));
         }
         else
         {
             return(new List <sysBpmsDocument>());
         }
     }
 }
Beispiel #4
0
        public ResultOperation Delete(Guid dynamicFormId)
        {
            ResultOperation resultOperation = null;

            try
            {
                resultOperation = new ResultOperation();
                if (resultOperation.IsSuccess)
                {
                    base.BeginTransaction();

                    List <sysBpmsStep> list = new StepService(this.UnitOfWork).GetList(null, dynamicFormId);
                    foreach (var item in list)
                    {
                        resultOperation = new StepService(this.UnitOfWork).Delete(item.ID);
                        if (!resultOperation.IsSuccess)
                        {
                            break;
                        }
                    }
                    if (resultOperation.IsSuccess)
                    {
                        sysBpmsDynamicForm dynamicForm = this.GetInfo(dynamicFormId);
                        this.UnitOfWork.Repository <IDynamicFormRepository>().Delete(dynamicFormId);

                        if (resultOperation.IsSuccess && dynamicForm.ApplicationPageID.HasValue)
                        {
                            //delete page variables
                            List <sysBpmsVariable> listVariable = new VariableService(this.UnitOfWork).GetList(null, dynamicForm.ApplicationPageID.Value, null, "", null, null);
                            foreach (var item in listVariable)
                            {
                                resultOperation = new VariableService(this.UnitOfWork).Delete(item.ID);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                            //delete application page
                            if (resultOperation.IsSuccess)
                            {
                                resultOperation = new ApplicationPageService(base.UnitOfWork).Delete(dynamicForm.ApplicationPageID.Value);
                            }
                        }
                    }
                    this.UnitOfWork.Save();
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }
        private ResultOperation SaveInto()
        {
            VariableService variableService = new VariableService(base.UnitOfWork);
            ResultOperation resultOperation = new ResultOperation();
            //Resort this.SetDataList because of variable dependencies.
            var listSetDataList = this.SetDataList.ToList();

            for (int i = 0; i < listSetDataList.Count; i++)
            {
                var             item     = listSetDataList[i];
                sysBpmsVariable variable = variableService.GetInfo(base.EngineSharedModel?.CurrentProcessID, base.EngineSharedModel?.CurrentApplicationPageID, item.Key, new string[] { $"{nameof(sysBpmsVariable.DependentVariableDependencies)}.{nameof(sysBpmsVariableDependency.ToVariable)}" });
                foreach (sysBpmsVariableDependency vDependency in variable.DependentVariableDependencies)
                {
                    var parentVariable = listSetDataList.Select((c, index) => new { item = c, index }).FirstOrDefault(c => c.item.Key != item.Key && c.item.Key == vDependency.ToVariable.Name && i < c.index);
                    //if variable has a dependency which has higher index ,this code block replace both of them.
                    if (parentVariable != null)
                    {
                        listSetDataList[i] = parentVariable.item;
                        listSetDataList[parentVariable.index] = item;
                        i--;
                    }
                }
            }
            this.SetDataList = listSetDataList.ToDictionary(c => c.Key, c => c.Value);

            //save variables.
            foreach (var item in this.SetDataList)
            {
                if (resultOperation.IsSuccess)
                {
                    sysBpmsVariable variable = variableService.GetInfo(base.EngineSharedModel?.CurrentProcessID, base.EngineSharedModel?.CurrentApplicationPageID, item.Key, new string[] { nameof(sysBpmsVariable.DependentVariableDependencies) });
                    if (variable != null)
                    {
                        switch ((sysBpmsVariable.e_RelationTypeLU)variable.RelationTypeLU)
                        {
                        case sysBpmsVariable.e_RelationTypeLU.Local:
                            resultOperation = new SystemicVariableTypeEngine(base.EngineSharedModel, variable, base.EngineSharedModel?.CurrentProcessID, this.ThreadID, this.AdditionalParams, this.UnitOfWork).SaveValues(item.Value);
                            break;

                        case sysBpmsVariable.e_RelationTypeLU.Entity:
                            resultOperation = new EntityVariableTypeEngine(base.EngineSharedModel, variable, base.EngineSharedModel?.CurrentProcessID, this.ThreadID, this.AdditionalParams, this.UnitOfWork).SaveValues(item.Value, this.SetDataList);
                            item.Value.SetValue("ID", resultOperation.CurrentObject);
                            break;

                        case sysBpmsVariable.e_RelationTypeLU.SqlQuery:
                            resultOperation = new SqlQueryVariableTypeEngine(base.EngineSharedModel, variable, base.EngineSharedModel?.CurrentProcessID, this.ThreadID, this.AdditionalParams, this.UnitOfWork).SaveValues(item.Value);
                            break;
                        }
                    }
                }
            }
            return(resultOperation);
        }
        public ResultOperation Delete(Guid EntityDefId)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                List <sysBpmsDocument> listDoc      = new DocumentService().GetList(null, EntityDefId, null, "", null, null, null);
                List <sysBpmsVariable> listVariable = new VariableService().GetList(null, null, null, "", EntityDefId, null);
                this.BeginTransaction();

                List <string> relatedEntity = this.GetList(EntityDefId);
                if (relatedEntity.Any())
                {
                    resultOperation.AddError($"This entity is related to {string.Join(",", relatedEntity)}");
                }

                if (listVariable.Count > 0)
                {
                    resultOperation.AddError(string.Format(LangUtility.Get("DeleteError.Text", nameof(sysBpmsEntityDef)), string.Join(" ,", listVariable.Select(d => d.Name))));
                }

                if (resultOperation.IsSuccess)
                {
                    DocumentService documentService = new DocumentService(base.UnitOfWork);
                    foreach (var item in listDoc)
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = documentService.Delete(item.GUID);
                        }
                    }

                    if (resultOperation.IsSuccess)
                    {
                        this.DropTable(this.GetInfo(EntityDefId));
                        this.UnitOfWork.Repository <IEntityDefRepository>().Delete(EntityDefId);
                        this.UnitOfWork.Save();
                    }
                    listDoc = null;
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);
            return(resultOperation);
        }
        /// <summary>
        /// this method make a list of variables name and Entity.PropertyName from variables which are object.
        /// </summary>
        public List <ComboTreeModel> GetVariableAsComboTree(Guid?ProcessID, Guid?ApplicationPageID, sysBpmsVariable.e_RelationTypeLU?notRelationTypeLU, string template = "")
        {
            List <ComboTreeModel>  Items     = new List <ComboTreeModel>();
            List <sysBpmsVariable> Variables = new VariableService(this.UnitOfWork).GetList(ProcessID, ApplicationPageID, null, "", null, true, new string[] { nameof(sysBpmsVariable.EntityDef) }).Where(c => (!notRelationTypeLU.HasValue || c.RelationTypeLU != (int)notRelationTypeLU) && c.VarTypeLU != (int)sysBpmsVariable.e_VarTypeLU.List).ToList();

            foreach (sysBpmsVariable item in Variables)
            {
                if (item.VarTypeLU == (int)sysBpmsVariable.e_VarTypeLU.Object)
                {
                    sysBpmsEntityDef entityDef = new EntityDefService(this.UnitOfWork).GetInfo(item.EntityDefID.Value);
                    Items.Add(new ComboTreeModel()
                    {
                        title = item.Name, id = item.Name, state = "closed",
                    });
                    foreach (EntityPropertyModel Property in entityDef.Properties.Where(c => c.IsActive))
                    {
                        Items.LastOrDefault().subs.Add(new ComboTreeModel()
                        {
                            title = item.Name + "." + Property.Name,
                            id    = !string.IsNullOrWhiteSpace(template) ? string.Format(template, (item.Name + "." + Property.Name)) :
                                    (item.Name + "." + Property.Name),
                        });
                    }
                    Items.LastOrDefault().subs.Add(new ComboTreeModel()
                    {
                        title = item.Name + ".ID",
                        id    = !string.IsNullOrWhiteSpace(template) ? string.Format(template, (item.Name + ".ID")) :
                                (item.Name + ".ID"),
                    });
                }
                else
                {
                    Items.Add(new ComboTreeModel()
                    {
                        title = item.Name,
                        id    = !string.IsNullOrWhiteSpace(template) ? string.Format(template, (item.Name)) : item.Name
                    });
                }
            }
            return(Items);
        }
        private VariableModel GetEntitiesByName(string VarName, List <QueryModel> additionalParams = null, PagingProperties currentPaging = null, string containerQuery = null, string[] includes = null)
        {
            if (additionalParams != null)
            {
                this.AdditionalParams = additionalParams;
            }

            if (!this.GetDataList.Any(c => c.Name == VarName))
            {
                sysBpmsVariable  _Variable  = new VariableService(base.UnitOfWork).GetInfo(base.EngineSharedModel?.CurrentProcessID, base.EngineSharedModel?.CurrentApplicationPageID, VarName, new string[] { nameof(sysBpmsVariable.DependentVariableDependencies) });
                List <DataModel> _DataModel = new List <DataModel>();
                if (_Variable != null)
                {
                    switch ((sysBpmsVariable.e_RelationTypeLU)_Variable.RelationTypeLU)
                    {
                    case sysBpmsVariable.e_RelationTypeLU.SqlQuery:
                        //this set each DataModel's key corresponding to returned columns by query and then set value into it.
                        _DataModel = new SqlQueryVariableTypeEngine(base.EngineSharedModel, _Variable, base.EngineSharedModel?.CurrentProcessID, this.ThreadID, this.AdditionalParams, base.UnitOfWork).GetResult(currentPaging, containerQuery);
                        break;

                    case sysBpmsVariable.e_RelationTypeLU.Local:
                        //this set each DataModel's key corresponding to variable name and then set value into it.
                        _DataModel = new SystemicVariableTypeEngine(base.EngineSharedModel, _Variable, base.EngineSharedModel?.CurrentProcessID, this.ThreadID, this.AdditionalParams, base.UnitOfWork).GetResult();
                        break;

                    case sysBpmsVariable.e_RelationTypeLU.Entity:
                        //this set each DataModel's key corresponding to returned columns by query and then set value into it.
                        //this method return one DataModel if the _Variable FilterTypeLU is Filtered otherwise it will return list of DataModel.
                        _DataModel = new EntityVariableTypeEngine(base.EngineSharedModel, _Variable, base.EngineSharedModel?.CurrentProcessID, this.ThreadID, this.AdditionalParams, base.UnitOfWork).GetResult(currentPaging, containerQuery, includes);
                        break;
                    }
                    this.GetDataList.Add(new VariableModel(VarName, _DataModel));
                }
            }
            return(this.GetDataList.FirstOrDefault(c => c.Name == VarName));
        }
        public ResultOperation Delete(Guid processId)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                this.BeginTransaction();
                sysBpmsProcess process = this.GetInfo(processId);
                if (this.GetList(null, process.ID).Any())
                {
                    resultOperation.AddError(LangUtility.Get("OldVersionDeleteError.Text", nameof(sysBpmsProcess)));
                }
                int countThread = new ThreadService().GetCount(process.ID);
                if (countThread > 0)
                {
                    resultOperation.AddError(string.Format(LangUtility.Get("DeleteProcessThreadError.Text", nameof(sysBpmsProcess)), countThread));
                }
                if (resultOperation.IsSuccess)
                {
                    //Delete Gateway
                    foreach (sysBpmsGateway gateway in new GatewayService(base.UnitOfWork).GetList(processId))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new GatewayService(base.UnitOfWork).Delete(gateway.ID);
                        }
                    }

                    //Delete Task
                    foreach (sysBpmsTask task in new TaskService(base.UnitOfWork).GetList(null, processId))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new TaskService(base.UnitOfWork).Delete(task.ID);
                        }
                    }

                    //Delete Event
                    foreach (sysBpmsEvent @event in new EventService(base.UnitOfWork).GetList(null, processId, "", null))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new EventService(base.UnitOfWork).Delete(@event.ID);
                        }
                    }

                    //Delete DynamicForm
                    foreach (sysBpmsDynamicForm dynamicForm in new DynamicFormService(base.UnitOfWork).GetList(processId, null, null, "", null, null))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new DynamicFormService(base.UnitOfWork).Delete(dynamicForm.ID);
                        }
                    }

                    //Delete Variable
                    foreach (sysBpmsVariable variable in new VariableService(base.UnitOfWork).GetList(processId, null, null, "", null, null))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new VariableService(base.UnitOfWork).Delete(variable.ID);
                        }
                    }

                    //Delete Process
                    if (resultOperation.IsSuccess)
                    {
                        this.UnitOfWork.Repository <IProcessRepository>().Delete(processId);
                        this.UnitOfWork.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);
            return(resultOperation);
        }
        public ResultOperation NewVersion(sysBpmsProcess current, string userName)
        {
            ResultOperation resultOperation;

            try
            {
                resultOperation = new ResultOperation();
                if (resultOperation.IsSuccess)
                {
                    if (this.GetList((int)sysBpmsProcess.Enum_StatusLU.Draft, current.ParentProcessID ?? current.ID).Any())
                    {
                        resultOperation.AddError(LangUtility.Get("NewVersionError.Text", nameof(sysBpmsProcess)));
                        return(resultOperation);
                    }
                    this.BeginTransaction();

                    //Create new process
                    sysBpmsProcess newProcess = this.GetInfo(current.ID);
                    newProcess.CreateDate      = DateTime.Now;
                    newProcess.UpdateDate      = DateTime.Now;
                    newProcess.StatusLU        = (int)sysBpmsProcess.Enum_StatusLU.Draft;
                    newProcess.ProcessVersion  = newProcess.ProcessVersion + 1;
                    newProcess.ParentProcessID = current.ParentProcessID.HasValue ? current.ParentProcessID.Value : current.ID;
                    newProcess.Number          = this.CalculateSerlialNumber(this.UnitOfWork.Repository <IProcessRepository>().MaxNumber() + 1);
                    newProcess.FormattedNumber = this.CalculateFormatNumber(newProcess.Number.Value, DateTime.Now.Date);

                    this.UnitOfWork.Repository <IProcessRepository>().Add(newProcess);
                    this.UnitOfWork.Save();
                    //Copy Variable
                    Dictionary <Guid, Guid> variableConvertID   = new Dictionary <Guid, Guid>();
                    VariableService         variableService     = new VariableService(base.UnitOfWork);
                    List <sysBpmsVariable>  sysBpmsVariableList = variableService.GetList(current.ID, null, null, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsVariable item in sysBpmsVariableList)
                        {
                            Guid oldGuidID = item.ID;
                            item.ProcessID  = newProcess.ID;
                            resultOperation = variableService.Add(item, null);
                            variableConvertID.Add(oldGuidID, item.ID);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy VariableDependency
                    VariableDependencyService        variableDependencyService     = new VariableDependencyService(base.UnitOfWork);
                    List <sysBpmsVariableDependency> sysBpmsVariableDependencyList = variableDependencyService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsVariableDependency item in sysBpmsVariableDependencyList)
                        {
                            if (item.ToVariableID.HasValue)
                            {
                                item.ToVariableID = variableConvertID[item.ToVariableID.Value];
                            }
                            item.DependentVariableID = variableConvertID[item.DependentVariableID];
                            resultOperation          = variableDependencyService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy Element
                    ElementService        elementService     = new ElementService(base.UnitOfWork);
                    List <sysBpmsElement> sysBpmsElementList = elementService.GetList(current.ID, null, "");
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsElement item in sysBpmsElementList)
                        {
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            resultOperation = elementService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy Lane
                    LaneService        laneService     = new LaneService(base.UnitOfWork);
                    List <sysBpmsLane> sysBpmsLaneList = laneService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsLane item in sysBpmsLaneList)
                        {
                            item.ID        = Guid.NewGuid();
                            item.ProcessID = newProcess.ID;
                            item.Element   = null;
                            laneService.Add(item);
                        }
                    }
                    //Copy event
                    EventService        eventService     = new EventService(base.UnitOfWork);
                    List <sysBpmsEvent> sysBpmsEventList = eventService.GetList(null, current.ID, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsEvent item in sysBpmsEventList)
                        {
                            item.ID         = Guid.NewGuid();
                            item.ProcessID  = newProcess.ID;
                            item.Element    = null;
                            resultOperation = eventService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy SequenceFlow
                    Dictionary <Guid, Guid>    flowConvertID           = new Dictionary <Guid, Guid>();
                    SequenceFlowService        sequenceFlowService     = new SequenceFlowService(base.UnitOfWork);
                    List <sysBpmsSequenceFlow> sysBpmsSequenceFlowList = sequenceFlowService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsSequenceFlow item in sysBpmsSequenceFlowList)
                        {
                            Guid flowNewId = Guid.NewGuid();
                            flowConvertID.Add(item.ID, flowNewId);
                            item.ID         = flowNewId;
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            item.Element    = null;
                            resultOperation = sequenceFlowService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy gateway
                    GatewayService        gatewayService     = new GatewayService(base.UnitOfWork);
                    ConditionService      conditionService   = new ConditionService(base.UnitOfWork);
                    List <sysBpmsGateway> sysBpmsGatewayList = gatewayService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsGateway item in sysBpmsGatewayList)
                        {
                            List <sysBpmsCondition> sysBpmsConditionList = conditionService.GetList(item.ID, null, null);
                            item.ID        = Guid.NewGuid();
                            item.ProcessID = newProcess.ID;
                            item.Element   = null;
                            if (item.DefaultSequenceFlowID.HasValue)
                            {
                                item.DefaultSequenceFlowID = flowConvertID[item.DefaultSequenceFlowID.Value];
                            }
                            resultOperation = gatewayService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                            foreach (sysBpmsCondition condition in sysBpmsConditionList)
                            {
                                condition.GatewayID = item.ID;
                                if (condition.SequenceFlowID.HasValue)
                                {
                                    condition.SequenceFlowID = flowConvertID[condition.SequenceFlowID.Value];
                                }
                                condition.Gateway      = null;
                                condition.SequenceFlow = null;
                                resultOperation        = conditionService.Add(condition);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //Copy dynamicForm
                    Dictionary <Guid, Guid>   formConvertID          = new Dictionary <Guid, Guid>();
                    DynamicFormService        dynamicFormService     = new DynamicFormService(base.UnitOfWork);
                    ApplicationPageService    applicationPageService = new ApplicationPageService(base.UnitOfWork);
                    List <sysBpmsDynamicForm> sysBpmsDynamicFormList = dynamicFormService.GetList(current.ID, null, null, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsDynamicForm item in sysBpmsDynamicFormList)
                        {
                            Guid oldID = item.ID;
                            item.ProcessId = newProcess.ID;
                            //First change code id.
                            dynamicFormService.UpdateBackendCodeID(item);
                            //Then update sourceCode value.
                            dynamicFormService.GetSourceCode(item);
                            item.Process    = null;
                            resultOperation = dynamicFormService.Add(item,
                                                                     item.ApplicationPageID.HasValue ? applicationPageService.GetInfo(item.ApplicationPageID.Value) : null, userName);
                            formConvertID.Add(oldID, item.ID);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Update formHtml control formid property
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsDynamicForm item in sysBpmsDynamicFormList)
                        {
                            if (item.DesignJson.Contains("formId"))
                            {
                                formConvertID.ToList().ForEach(c =>
                                {
                                    item.DesignJson = item.DesignJson.Replace(c.Key.ToString(), c.Value.ToString());
                                });
                                resultOperation = dynamicFormService.Update(item, userName);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //Copy task
                    TaskService        taskService     = new TaskService(base.UnitOfWork);
                    StepService        stepService     = new StepService(base.UnitOfWork);
                    List <sysBpmsTask> sysBpmsTaskList = taskService.GetList(null, current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsTask item in sysBpmsTaskList)
                        {
                            List <sysBpmsStep> sysBpmsStepList = stepService.GetList(item.ID, null);
                            item.ID         = Guid.NewGuid();
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            item.Element    = null;
                            resultOperation = taskService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                            foreach (sysBpmsStep step in sysBpmsStepList)
                            {
                                step.TaskID = item.ID;
                                if (step.DynamicFormID.HasValue)
                                {
                                    step.DynamicFormID = formConvertID[step.DynamicFormID.Value];
                                }
                                step.DynamicForm = null;
                                step.Task        = null;
                                resultOperation  = stepService.Add(step);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    this.UnitOfWork.Save();
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }