Пример #1
0
        List <WorkFlowInfo> IManagerWorkFlow.GetAllWorkFlowDetails(Guid tenantId, string entityname)
        {
            var entityId  = iMetadataManager.GetEntityContextByEntityName(entityname);
            var workFlows = _reviewWorkFlow.GetWorkFlows(tenantId, entityId);
            var subTypes  = iMetadataManager.GetSubTypesDetails(entityname);

            if (workFlows != null && workFlows.Count > 0)
            {
                var allSteps    = WorkFlowHelper.GetAllSteps(entityId);
                var workFlowIds = workFlows.Select(p => p.WorkFlowId).ToList();

                var workFlowSteps      = _managerWorkFlowStep.GetWorkFlowStepsByWorkFlowIds(tenantId, workFlowIds);
                var workFlowInnerSteps = _managerWorkFlowInnerStep.GetWorkFlowInnerStepByWorkFlowIds(tenantId, workFlowIds);
                var roles = _managerWorkFlowRole.GetWorkFlowRolesByWorkFlowIds(tenantId, workFlowIds).ToList();
                foreach (var workFlow in workFlows)
                {
                    var thisWorkFlowRoles = (from role in roles where role.WorkFlowId == workFlow.WorkFlowId select role).ToList();
                    var allWorkFlowSteps  = new List <WorkFlowStepInfo>();
                    var allStepSavedCount = (from workFlowStep in workFlowSteps where workFlowStep.WorkFlowId == workFlow.WorkFlowId
                                             orderby workFlowStep.SequenceNumber descending select workFlowStep.SequenceNumber).FirstOrDefault();
                    foreach (var step in allSteps)
                    {
                        //return saved step
                        var checkStepsSaved = (from workFlowStep in workFlowSteps where workFlowStep.WorkFlowId == workFlow.WorkFlowId &&
                                               workFlowStep.TransitionType.Id == step.Id select workFlowStep).FirstOrDefault();

                        var checkRoles = (from role in thisWorkFlowRoles where role.WorkFlowStepId == checkStepsSaved.WorkFlowStepId select role).ToList();

                        if (checkStepsSaved != null)
                        {
                            checkStepsSaved.TransitionType.Name = step.Key;
                            checkStepsSaved.WorkFlowId          = workFlow.WorkFlowId;
                            checkStepsSaved.Roles = checkRoles;
                            allWorkFlowSteps.Add(checkStepsSaved);
                        }
                    }

                    foreach (var workFlowStep in allWorkFlowSteps)
                    {
                        var itsInnerSteps = (from workFlowInnerStep in workFlowInnerSteps where workFlowInnerStep.WorkFlowId == workFlow.WorkFlowId &&
                                             workFlowInnerStep.WorkFlowStepId == workFlowStep.WorkFlowStepId
                                             select workFlowInnerStep).ToList();

                        foreach (var workFlowInnerStep in itsInnerSteps)
                        {
                            workFlowInnerStep.TransitionType.Name = (from allStep in allSteps where allStep.Id == workFlowInnerStep.TransitionType.Id select allStep.Key).FirstOrDefault();
                        }
                        workFlowStep.InnerSteps = itsInnerSteps.OrderBy(p => p.SequenceNumber).ToList();
                    }

                    workFlow.Steps = allWorkFlowSteps.OrderBy(p => p.SequenceNumber).ToList();
                    //Chnage sab typesId To name
                    var mapped = subTypes.FirstOrDefault(t => t.Key.Equals(workFlow.SubTypeCode));
                    if (mapped.Key != null)
                    {
                        workFlow.SubTypeCode = mapped.Value;
                    }
                    workFlow.EntityId = entityname;
                }
            }
            return(workFlows);
        }
        bool IManagerWorkFlowSecurity.InitializeTenantWorkFlow(Guid rootTenantId, Guid newTenantId, List <string> entityIds)
        {
            List <RoleInfo> newRoles = new List <RoleInfo>();
            var             allRoles = _managerRole.Roles(rootTenantId);

            foreach (var allRole in allRoles)
            {
                var itsRole = new RoleInfo();
                DataUtility.CopyPropertiesTo(allRole, itsRole);
                itsRole.RoleId = Guid.NewGuid();
                newRoles.Add(itsRole);
            }
            //Init roles
            _managerRole.CreateRoles(newTenantId, newRoles);

            var workFlows = _managerWorkFlow.GetWorkFlowsByEntityIds(rootTenantId, entityIds);

            if (workFlows.Count > 0)
            {
                //Get root tenant
                var workFlowIds          = workFlows.Select(p => p.WorkFlowId).ToList();
                var workFlowSteps        = _managerWorkFlowStep.GetWorkFlowStepsByWorkFlowIds(rootTenantId, workFlowIds);
                var workFlowInnerSteps   = _managerInnerStep.GetWorkFlowInnerStepByWorkFlowIds(rootTenantId, workFlowIds);
                var workFlowOperations   = _managerOperation.GetWorkFlowOperationsByWorkFlowIds(rootTenantId, workFlowIds);
                var workFlowProcess      = _managerWorkFlowProcess.GetWorkFlowProcessByWorkFlowIds(rootTenantId, workFlowIds);
                var workFlowProcessTasks = _managerWorkFlowProcessTask.GetWorkFlowProcessTaskByWorkFlowIds(rootTenantId, workFlowIds);
                var workFlowRoles        = _managerWorkFlowRole.GetWorkFlowRolesByWorkFlowIds(rootTenantId, workFlowIds);

                List <WorkFlowInfo>            newWorkFlows     = new List <WorkFlowInfo>();
                List <WorkFlowStepInfo>        newWorkFlowSteps = new List <WorkFlowStepInfo>();
                List <WorkFlowInnerStepInfo>   newInnerSteps    = new List <WorkFlowInnerStepInfo>();
                List <WorkFlowOperationInfo>   newOperations    = new List <WorkFlowOperationInfo>();
                List <WorkFlowProcessInfo>     newProcess       = new List <WorkFlowProcessInfo>();
                List <WorkFlowProcessTaskInfo> newProcessTasks  = new List <WorkFlowProcessTaskInfo>();
                List <WorkFlowRoleInfo>        newWorkFlowRoles = new List <WorkFlowRoleInfo>();

                foreach (var workFlow in workFlows)
                {
                    var itsWorkFlow = new WorkFlowInfo();
                    DataUtility.CopyPropertiesTo(workFlow, itsWorkFlow);
                    itsWorkFlow.WorkFlowId = Guid.NewGuid();

                    //Filter steps
                    var filterWorkFlowSteps = (from workFlowStep in workFlowSteps where workFlowStep.WorkFlowId == workFlow.WorkFlowId select workFlowStep).ToList();
                    foreach (var filterWorkFlowStep in filterWorkFlowSteps)
                    {
                        var itsStep = new WorkFlowStepInfo();
                        DataUtility.CopyPropertiesTo(filterWorkFlowStep, itsStep);
                        itsStep.WorkFlowId     = itsWorkFlow.WorkFlowId;
                        itsStep.WorkFlowStepId = Guid.NewGuid();

                        //Filter Inner steps
                        var filterInnerSteps = (from innerStep in workFlowInnerSteps where innerStep.WorkFlowStepId == filterWorkFlowStep.WorkFlowStepId &&
                                                innerStep.WorkFlowId == workFlow.WorkFlowId select innerStep).ToList();

                        foreach (var filterInnerStep in filterInnerSteps)
                        {
                            var itsInnerStep = new WorkFlowInnerStepInfo();;
                            DataUtility.CopyPropertiesTo(filterInnerStep, itsInnerStep);
                            itsInnerStep.InnerStepId    = Guid.NewGuid();
                            itsInnerStep.WorkFlowId     = itsWorkFlow.WorkFlowId;
                            itsInnerStep.WorkFlowStepId = itsStep.WorkFlowStepId;
                            //Filter Process
                            var filterProcess = (from workFlowProcs in workFlowProcess where workFlowProcs.OperationOrTransactionId == filterInnerStep.InnerStepId &&
                                                 workFlowProcs.WorkFlowId == workFlow.WorkFlowId select workFlowProcs).ToList();

                            foreach (var filterProces in filterProcess)
                            {
                                var itsProcess = new WorkFlowProcessInfo();
                                DataUtility.CopyPropertiesTo(filterProces, itsProcess);

                                itsProcess.WorkFlowProcessId        = Guid.NewGuid();
                                itsProcess.WorkFlowId               = itsWorkFlow.WorkFlowId;
                                itsProcess.OperationOrTransactionId = itsInnerStep.InnerStepId;

                                //Filter process tasks
                                var filterProcessTasks = (from processTask in workFlowProcessTasks where processTask.WorkFlowProcessId == filterProces.WorkFlowProcessId &&
                                                          processTask.WorkFlowId == workFlow.WorkFlowId select processTask).ToList();

                                foreach (var filterProcessTask in filterProcessTasks)
                                {
                                    var itsTasks = new WorkFlowProcessTaskInfo();
                                    DataUtility.CopyPropertiesTo(filterProcessTask, itsTasks);
                                    itsTasks.WorkFlowProcessTaskId = Guid.NewGuid();
                                    itsTasks.WorkFlowId            = itsWorkFlow.WorkFlowId;
                                    itsTasks.WorkFlowProcessId     = itsProcess.WorkFlowProcessId;
                                    newProcessTasks.Add(itsTasks);
                                }

                                newProcess.Add(itsProcess);
                            }

                            newInnerSteps.Add(itsInnerStep);
                        }

                        //Filter roles

                        var filterRoles = (from workFlowRole in workFlowRoles where workFlowRole.WorkFlowStepId == filterWorkFlowStep.WorkFlowStepId &&
                                           workFlowRole.WorkFlowId == workFlow.WorkFlowId select workFlowRole).ToList();

                        foreach (var filterRole in filterRoles)
                        {
                            var roleId = Guid.Empty;
                            var rootTenantRoleFilter = (from allRole in allRoles where allRole.RoleId == filterRole.RoleId select allRole).ToList();
                            if (rootTenantRoleFilter.Count > 0)
                            {
                                roleId = (from newRole in newRoles where newRole.Name == rootTenantRoleFilter[0].Name select newRole.RoleId).FirstOrDefault();
                            }
                            var itsRole = new WorkFlowRoleInfo();
                            DataUtility.CopyPropertiesTo(filterRole, itsRole);
                            itsRole.RoleAssignmetId = Guid.NewGuid();
                            itsRole.WorkFlowId      = itsWorkFlow.WorkFlowId;
                            itsRole.WorkFlowStepId  = itsStep.WorkFlowStepId;
                            itsRole.RoleId          = roleId;

                            newWorkFlowRoles.Add(itsRole);
                        }

                        newWorkFlowSteps.Add(itsStep);
                    }

                    //Filter Operation*****************************************
                    var filterOperations = (from workFlowOperation in workFlowOperations where workFlowOperation.WorkFlowId == workFlow.WorkFlowId select workFlowOperation).ToList();
                    foreach (var filterOperation in filterOperations)
                    {
                        var itsOperation = new WorkFlowOperationInfo();
                        DataUtility.CopyPropertiesTo(filterOperation, itsOperation);
                        itsOperation.WorkFlowOperationId = Guid.NewGuid();
                        itsOperation.WorkFlowId          = itsWorkFlow.WorkFlowId;

                        //filter process
                        var filterProcess = (from workFlowProcs in workFlowProcess where workFlowProcs.OperationOrTransactionId == filterOperation.WorkFlowOperationId &&
                                             workFlowProcs.WorkFlowId == workFlow.WorkFlowId select workFlowProcs).ToList();

                        foreach (var filterProces in filterProcess)
                        {
                            var itsProcess = new WorkFlowProcessInfo();
                            DataUtility.CopyPropertiesTo(filterProces, itsProcess);

                            itsProcess.WorkFlowProcessId        = Guid.NewGuid();
                            itsProcess.WorkFlowId               = itsWorkFlow.WorkFlowId;
                            itsProcess.OperationOrTransactionId = itsOperation.WorkFlowOperationId;

                            //Filter process tasks
                            var filterProcessTasks = (from processTask in workFlowProcessTasks where processTask.WorkFlowProcessId == filterProces.WorkFlowProcessId &&
                                                      processTask.WorkFlowId == workFlow.WorkFlowId select processTask).ToList();

                            foreach (var filterProcessTask in filterProcessTasks)
                            {
                                var itsTasks = new WorkFlowProcessTaskInfo();
                                DataUtility.CopyPropertiesTo(filterProcessTask, itsTasks);
                                itsTasks.WorkFlowProcessTaskId = Guid.NewGuid();
                                itsTasks.WorkFlowId            = itsWorkFlow.WorkFlowId;
                                itsTasks.WorkFlowProcessId     = itsProcess.WorkFlowProcessId;
                                newProcessTasks.Add(itsTasks);
                            }

                            newProcess.Add(itsProcess);
                        }


                        newOperations.Add(itsOperation);
                    }


                    newWorkFlows.Add(itsWorkFlow);
                }

                //Init workflow
                if (newWorkFlows.Count > 0)
                {
                    _managerWorkFlow.CreateWorkFlows(newTenantId, newWorkFlows);
                }
                if (newOperations.Count > 0)
                {
                    _managerOperation.CreateWorkFlowOperations(newTenantId, newOperations);
                }
                if (newWorkFlowSteps.Count > 0)
                {
                    _managerWorkFlowStep.CreateWorkFlowSteps(newTenantId, newWorkFlowSteps);
                }
                if (newInnerSteps.Count > 0)
                {
                    _managerInnerStep.CreateWorkFlowInnerSteps(newTenantId, newInnerSteps);
                }
                if (newProcess.Count > 0)
                {
                    _managerWorkFlowProcess.CreateWorkFlowProcess(newTenantId, newProcess);
                }
                if (newProcessTasks.Count > 0)
                {
                    _managerWorkFlowProcessTask.CreateWorkFlowProcessTasks(newTenantId, newProcessTasks);
                }
                if (newWorkFlowRoles.Count > 0)
                {
                    _managerWorkFlowRole.CreateWorkFlowRoles(newTenantId, newWorkFlowRoles);
                }
            }

            return(true);
        }