示例#1
0
        public IActionResult Get([FromRoute] string entityname, [FromQuery]  Guid transitionType, [FromQuery] Guid workFlowId)
        {
            try
            {
                var stopwatch = StopwatchLogger.Start(_log);
                _log.Info("Called WorkFlowStepController Get {0}=", JsonConvert.SerializeObject(entityname));
                var entityId           = _iMetadataManager.GetEntityContextByEntityName(entityname);
                var retVal             = WorkFlowHelper.GetAllSteps(entityId);
                var itsSavedInnerSteps = _managerWorkFlowInnerSteps.GetWorkFlowInnerStep_ByStepTransactionType(TenantCode, transitionType, workFlowId);
                if (retVal.Count > 0)
                {
                    retVal = (from retV in retVal where retV.Id != transitionType select retV).ToList();
                }
                List <WorkFlowResource> filteredInnerSteps = new List <WorkFlowResource>();
                foreach (var retV in retVal)
                {
                    var checkExistance = (from itsSavedInnerStep in itsSavedInnerSteps where itsSavedInnerStep.TransitionType.Id == retV.Id select itsSavedInnerStep).ToList();
                    if (checkExistance.Count == 0)
                    {
                        filteredInnerSteps.Add(retV);
                    }
                }

                stopwatch.StopAndLog("End WorkFlowStepController Get");
                return(Ok(filteredInnerSteps));
            }
            catch (Exception ex)
            {
                _log.Error(ExceptionFormatter.SerializeToString(ex));
                return(StatusCode((int)HttpStatusCode.InternalServerError, ApiConstant.CustomErrorMessage));
            }
        }
        WorkFlowInfo IManagerWorkFlow.GetWorkFlowDetail(Guid tenantId, string entityname, string subTypeName)
        {
            var entityId    = iMetadataManager.GetEntityContextByEntityName(entityname);
            var subTypeCode = iMetadataManager.GetSubTypeId(entityname, subTypeName);
            var workFlow    = _reviewWorkFlow.GetWorkFlow(tenantId, entityId, subTypeCode);

            if (workFlow != null)
            {
                var workflowOperations = _managerWorkFlowOperation.GetWorkFlowOperations(tenantId, workFlow.WorkFlowId);
                workFlow.Operations = workflowOperations;
                //Get all steps from statci class
                var allSteps = WorkFlowHelper.GetAllSteps(entityId);

                var workFlowSteps      = _managerWorkFlowStep.GetWorkFlowSteps(tenantId, workFlow.WorkFlowId);
                var workFlowInnerSteps = _managerWorkFlowInnerStep.GetWorkFlowInnerStep(tenantId, workFlow.WorkFlowId);
                var workFlowProcess    = _managerWorkFlowProcess.GetWorkFlowProcess(tenantId, workFlow.WorkFlowId);

                // var workFlowProcessTasks=_managerWorkFlowProcessTask.GetWorkFlowProcessTask(tenantId,workFlow.WorkFlowId);
                var allWorkFlowSteps  = new List <WorkFlowStepInfo>();
                var allStepSavedCount = (from workFlowStep in workFlowSteps orderby workFlowStep.SequenceNumber descending select workFlowStep.SequenceNumber).FirstOrDefault();
                foreach (var step in allSteps)
                {
                    //return saved step
                    var checkStepsSaved = (from workFlowStep in workFlowSteps where workFlowStep.TransitionType.Id == step.Id select workFlowStep).FirstOrDefault();
                    if (checkStepsSaved != null)
                    {
                        checkStepsSaved.TransitionType.Name = step.Key;
                        checkStepsSaved.WorkFlowId          = workFlow.WorkFlowId;
                        allWorkFlowSteps.Add(checkStepsSaved);
                    }
                    else
                    {
                        //return not saved step
                        allWorkFlowSteps.Add(new WorkFlowStepInfo
                        {
                            WorkFlowStepId = Guid.Empty,
                            WorkFlowId     = workFlow.WorkFlowId,
                            SequenceNumber = ++allStepSavedCount,
                            TransitionType = new ItemName {
                                Id = step.Id, Name = step.Key
                            }
                        });
                    }
                }

                foreach (var workFlowStep in allWorkFlowSteps)
                {
                    var itsInnerSteps = (from workFlowInnerStep in workFlowInnerSteps where
                                         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();

                        workFlowInnerStep.WorkFlowProcess = (from workFlowPro in workFlowProcess
                                                             where workFlowPro.OperationOrTransactionId == workFlowInnerStep.InnerStepId
                                                             select workFlowPro).ToList();
                    }

                    workFlowStep.InnerSteps = itsInnerSteps.OrderBy(p => p.SequenceNumber).ToList();
                }

                workFlow.Steps = allWorkFlowSteps.OrderBy(p => p.SequenceNumber).ToList();

                //Chnage sab typesId To name
                workFlow.SubTypeCode = subTypeName;
                workFlow.EntityId    = entityname;
            }


            return(workFlow);
        }
        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.InitializeRootTenantWorkFlow(Guid tenantId, string entityId)
        {
            var allEntities = iMetadataManager.GetEntities(false);
            // Filtwer all  Workflow supported entity
            var workFlowEntities = (from allEntity in allEntities where allEntity.SupportWorkflow && allEntity.Name == entityId select allEntity).ToList();

            foreach (var workFlowEntity in workFlowEntities)
            {
                var entityContextAll = iMetadataManager.GetEntitityByName(workFlowEntity.Name);
                var entityContext    = iMetadataManager.GetEntityContextByEntityName(workFlowEntity.Name);
                foreach (var subtype in workFlowEntity.Subtypes)
                {
                    var workflowInfo = new WorkFlowInfo
                    {
                        WorkFlowId  = Guid.NewGuid(),
                        EntityId    = entityContext,
                        Status      = true,
                        SubTypeCode = iMetadataManager.GetSubTypeId(workFlowEntity.Name, subtype)
                    };
                    _managerWorkFlow.CreateWorkFlow(tenantId, workflowInfo);

                    //all steps from static classes (Transition)
                    List <WorkFlowResource> allSteps = WorkFlowHelper.GetAllSteps(entityContext);
                    var count = 0;
                    foreach (var allStep in allSteps)
                    {
                        var workFlowStep = new WorkFlowStepInfo
                        {
                            WorkFlowId     = workflowInfo.WorkFlowId,
                            TransitionType = new ItemName {
                                Id = allStep.Id
                            },
                            SequenceNumber = count++
                        };
                        workFlowStep.WorkFlowStepId = _managerWorkFlowStep.CreateWorkFlowStep(tenantId, workFlowStep);
                    }

                    // (Operations)
                    List <WorkFlowOperationInfo> workFlowOperations = new List <WorkFlowOperationInfo>();
                    foreach (var entityCon in entityContextAll.Operations)
                    {
                        if (entityCon.Name == "Create")
                        {
                            workFlowOperations.Add(new WorkFlowOperationInfo
                            {
                                WorkFlowOperationId = Guid.NewGuid(),
                                OperationType       = WorkFlowOperationType.Create,
                                WorkFlowId          = workflowInfo.WorkFlowId
                            });
                        }
                        else if (entityCon.Name == "Update")
                        {
                            workFlowOperations.Add(new WorkFlowOperationInfo
                            {
                                WorkFlowOperationId = Guid.NewGuid(),
                                OperationType       = WorkFlowOperationType.Update,
                                WorkFlowId          = workflowInfo.WorkFlowId
                            });
                        }
                        else if (entityCon.Name == "Delete")
                        {
                            workFlowOperations.Add(new WorkFlowOperationInfo
                            {
                                WorkFlowOperationId = Guid.NewGuid(),
                                OperationType       = WorkFlowOperationType.Delete,
                                WorkFlowId          = workflowInfo.WorkFlowId
                            });
                        }
                        else if (entityCon.Name == "UpdateStatus")
                        {
                            workFlowOperations.Add(new WorkFlowOperationInfo
                            {
                                WorkFlowOperationId = Guid.NewGuid(),
                                OperationType       = WorkFlowOperationType.UpdateStatus,
                                WorkFlowId          = workflowInfo.WorkFlowId
                            });
                        }
                    }
                    _managerOperation.CreateWorkFlowOperations(tenantId, workFlowOperations);
                    count = 0;
                    List <WorkFlowProcessInfo> workFlowProcesses = new List <WorkFlowProcessInfo>();
                    foreach (var workFlowOperation in workFlowOperations)
                    {
                        workFlowProcesses.Add(new WorkFlowProcessInfo
                        {
                            WorkFlowProcessId          = Guid.NewGuid(),
                            WorkFlowId                 = workflowInfo.WorkFlowId,
                            OperationOrTransactionId   = workFlowOperation.WorkFlowOperationId,
                            OperationOrTransactionType = (int)OperationOrTransactionType.Operation,
                            ProcessType                = (int)WorkFlowProcessType.PreProcess
                        });

                        workFlowProcesses.Add(new WorkFlowProcessInfo
                        {
                            WorkFlowProcessId          = Guid.NewGuid(),
                            WorkFlowId                 = workflowInfo.WorkFlowId,
                            OperationOrTransactionId   = workFlowOperation.WorkFlowOperationId,
                            OperationOrTransactionType = (int)OperationOrTransactionType.Operation,
                            ProcessType                = (int)WorkFlowProcessType.Process
                        });
                        workFlowProcesses.Add(new WorkFlowProcessInfo
                        {
                            WorkFlowProcessId          = Guid.NewGuid(),
                            WorkFlowId                 = workflowInfo.WorkFlowId,
                            OperationOrTransactionId   = workFlowOperation.WorkFlowOperationId,
                            OperationOrTransactionType = (int)OperationOrTransactionType.Operation,
                            ProcessType                = (int)WorkFlowProcessType.PostProcess
                        });
                    }
                    _managerWorkFlowProcess.CreateWorkFlowProcess(tenantId, workFlowProcesses);
                }
            }

            return(true);
        }
        object IManagerWorkFlowSecurity.GetWorkFlowSecurity(Guid tenantId, string entityname)
        {
            var subTypes      = iMetadataManager.GetSubTypesDetails(entityname);
            var entityId      = iMetadataManager.GetEntityContextByEntityName(entityname);
            var workFlowItems = _managerWorkFlow.GetWorkFlows(tenantId, entityname);
            var allRoles      = _managerRole.Roles(tenantId);
            var mainObj       = new { roleList = allRoles, workFlows = new List <object>() };
            var allSteps      = WorkFlowHelper.GetAllSteps(entityId);
            var workFlowSteps = _managerWorkFlowStep.GetWorkFlowStepsByWorkFlowIds(tenantId, workFlowItems.Select(p => p.WorkFlowId).ToList());
            var roles         = _managerWorkFlowRole.GetWorkFlowRolesByWorkFlowIds(tenantId, workFlowItems.Select(p => p.WorkFlowId).ToList());

            foreach (var workFlowItem in workFlowItems)
            {
                var subTypeName       = subTypes.FirstOrDefault(t => t.Key.Equals(workFlowItem.SubTypeCode));
                var thisWorkFlowRoles = (from role in roles where role.WorkFlowId == workFlowItem.WorkFlowId select role).ToList();
                var workFLowObj       = new
                {
                    EntityId    = entityname,
                    SubTypeCode = subTypeName.Value,
                    WorkFlowId  = workFlowItem.WorkFlowId,
                    Steps       = new List <object>()
                };

                var thisWorkFLowSteps = (from workFlowStep in workFlowSteps where workFlowStep.WorkFlowId == workFlowItem.WorkFlowId select workFlowStep).ToList();
                foreach (var step in allSteps)
                {
                    var filteredStep = (from workFlowStep in thisWorkFLowSteps where workFlowStep.TransitionType.Id == step.Id select workFlowStep).FirstOrDefault();
                    if (filteredStep != null)
                    {
                        var stepObj = new
                        {
                            filteredStep.WorkFlowStepId,
                            filteredStep.WorkFlowId,
                            Name = step.Value,
                            filteredStep.IsAssigmentMandatory,
                            filteredStep.AllotedTime,
                            filteredStep.CriticalTime,
                            ActivatedList = new List <object>(),
                            AccessedList  = new List <object>(),
                            AssignedList  = new List <object>()
                        };


                        var checkRoles = (from role in thisWorkFlowRoles where role.WorkFlowStepId == filteredStep.WorkFlowStepId select role).ToList();
                        if (checkRoles.Count > 0)
                        {
                            foreach (var checkRole in checkRoles)
                            {
                                var rolObj = new
                                {
                                    checkRole.RoleAssignmetId,
                                    checkRole.RoleId,
                                    checkRole.WorkFlowId,
                                    checkRole.WorkFlowStepId,
                                    name = checkRole.RoleName,
                                    checkRole.AssignmentOperationType
                                };
                                if (checkRole.AssignmentOperationType == (int)WorkFlowRoleType.ActivatedRoles)
                                {
                                    stepObj.ActivatedList.Add(rolObj);
                                }
                                if (checkRole.AssignmentOperationType == (int)WorkFlowRoleType.AccessedRoles)
                                {
                                    stepObj.AccessedList.Add(rolObj);
                                }
                                if (checkRole.AssignmentOperationType == (int)WorkFlowRoleType.AssignedRoles)
                                {
                                    stepObj.AssignedList.Add(rolObj);
                                }
                            }
                        }
                        workFLowObj.Steps.Add(stepObj);
                    }
                }
                mainObj.workFlows.Add(workFLowObj);
            }
            return(mainObj);
        }
        List <WorkFlowInfo> IManagerWorkFlowSecurity.GetWorkFlowsByUserCode(Guid tenantId, Guid userId, bool isSuperAdmin)
        {
            var workFlowSteps      = _managerWorkFlowStep.GetWorkFlowStepsByUserId(tenantId, userId, isSuperAdmin);
            var workFlows          = _managerWorkFlow.GetWorkFlowsByIds(tenantId, workFlowSteps.Select(p => p.WorkFlowId).Distinct().ToList());
            var workFlowOperations = _managerOperation.GetWorkFlowOperationsByWorkFlowIds(tenantId, workFlows.Select(p => p.WorkFlowId).ToList());

            var workFlowInnerSteps        = _managerInnerStep.GetWorkFlowInnerStep_ByStepIds(tenantId, workFlowSteps.Select(p => p.WorkFlowStepId).ToList());
            var operationOrTransactionIds = new List <Guid>();

            operationOrTransactionIds.AddRange(workFlowOperations.Select(p => p.WorkFlowOperationId).ToList());
            operationOrTransactionIds.AddRange(workFlowInnerSteps.Select(p => p.InnerStepId).ToList());
            var workFlowProcess = _managerWorkFlowProcess.GetWorkFlowProcessByOperationOrTransitionIds(tenantId, operationOrTransactionIds);
            var processTasks    = _managerWorkFlowProcessTask.GetWorkFlowProcessTask_ByProcessIds(tenantId, workFlowProcess.Select(proc => proc.WorkFlowProcessId).ToList());
            var workFlowRoles   = _managerWorkFlowRole.GetWorkFlowRolesByStepIds(tenantId, workFlowSteps.Select(p => p.WorkFlowStepId).ToList());

            foreach (var workFlow in workFlows)
            {
                //get its operations
                workFlow.Operations = (from workFlowOperation in workFlowOperations where workFlowOperation.WorkFlowId == workFlow.WorkFlowId select workFlowOperation).ToList();
                //set process to operation
                foreach (var operation in workFlow.Operations)
                {
                    operation.WorkFlowProcess = (from workFlowPro in workFlowProcess where workFlowPro.OperationOrTransactionId == operation.WorkFlowOperationId &&
                                                 workFlowPro.WorkFlowId == workFlow.WorkFlowId select workFlowPro).ToList();
                    foreach (var process in operation.WorkFlowProcess)
                    {
                        process.WorkFlowProcessTasks = new List <WorkFlowProcessTaskInfo>();
                        if (process.ProcessType == (int)WorkFlowProcessType.PreProcess)
                        {
                            process.WorkFlowProcessTasks.AddRange((from allProcessTask in processTasks
                                                                   where process.WorkFlowProcessId == allProcessTask.WorkFlowProcessId && process.WorkFlowId == workFlow.WorkFlowId
                                                                   orderby allProcessTask.SequenceCode
                                                                   select allProcessTask).ToList());
                        }

                        if (process.ProcessType == (int)WorkFlowProcessType.Process)
                        {
                            process.WorkFlowProcessTasks.AddRange((from allProcessTask in processTasks
                                                                   where process.WorkFlowProcessId == allProcessTask.WorkFlowProcessId && process.WorkFlowId == workFlow.WorkFlowId
                                                                   orderby allProcessTask.SequenceCode
                                                                   select allProcessTask).ToList());
                        }

                        if (process.ProcessType == (int)WorkFlowProcessType.PostProcess)
                        {
                            process.WorkFlowProcessTasks.AddRange((from allProcessTask in processTasks
                                                                   where process.WorkFlowProcessId == allProcessTask.WorkFlowProcessId && process.WorkFlowId == workFlow.WorkFlowId
                                                                   orderby allProcessTask.SequenceCode
                                                                   select allProcessTask).ToList());
                        }
                    }
                }

                //get its steps
                workFlow.Steps = new List <WorkFlowStepInfo>();
                var allSteps         = WorkFlowHelper.GetAllSteps(workFlow.EntityId);
                var itsWorkFlowSteps = (from workFlowStep in workFlowSteps where workFlowStep.WorkFlowId == workFlow.WorkFlowId select workFlowStep).ToList();

                foreach (var itsWorkFlowStep in itsWorkFlowSteps)
                {
                    //filter its role
                    itsWorkFlowStep.Roles = (from workFlowRole in workFlowRoles where workFlowRole.WorkFlowStepId == itsWorkFlowStep.WorkFlowStepId &&
                                             workFlowRole.WorkFlowId == workFlow.WorkFlowId select workFlowRole).ToList();
                    var filteredStep = (from allStep in allSteps where itsWorkFlowStep.TransitionType.Id == allStep.Id select allStep).FirstOrDefault();
                    itsWorkFlowStep.TransitionType.Name = filteredStep.Value;
                    //filter its inner steps
                    var itsInnerSteps = (from workFlowInnerStep in workFlowInnerSteps where workFlowInnerStep.WorkFlowStepId == itsWorkFlowStep.WorkFlowStepId &&
                                         workFlowInnerStep.WorkFlowId == workFlow.WorkFlowId select workFlowInnerStep).ToList();
                    if (itsInnerSteps.Count > 0)
                    {
                        //filter Inner step process
                        foreach (var itsInnerStep in itsInnerSteps)
                        {
                            itsInnerStep.WorkFlowProcess = (from workFlowPro in workFlowProcess where workFlowPro.OperationOrTransactionId == itsInnerStep.InnerStepId &&
                                                            workFlowPro.WorkFlowId == workFlow.WorkFlowId select workFlowPro).ToList();

                            foreach (var process in itsInnerStep.WorkFlowProcess)
                            {
                                process.WorkFlowProcessTasks = new List <WorkFlowProcessTaskInfo>();
                                if (process.ProcessType == (int)WorkFlowProcessType.PreProcess)
                                {
                                    process.WorkFlowProcessTasks.AddRange((from allProcessTask in processTasks
                                                                           where process.WorkFlowProcessId == allProcessTask.WorkFlowProcessId && process.WorkFlowId == workFlow.WorkFlowId
                                                                           orderby allProcessTask.SequenceCode
                                                                           select allProcessTask).ToList());
                                }

                                if (process.ProcessType == (int)WorkFlowProcessType.Process)
                                {
                                    process.WorkFlowProcessTasks.AddRange((from allProcessTask in processTasks
                                                                           where process.WorkFlowProcessId == allProcessTask.WorkFlowProcessId && process.WorkFlowId == workFlow.WorkFlowId
                                                                           orderby allProcessTask.SequenceCode
                                                                           select allProcessTask).ToList());
                                }

                                if (process.ProcessType == (int)WorkFlowProcessType.PostProcess)
                                {
                                    process.WorkFlowProcessTasks.AddRange((from allProcessTask in processTasks
                                                                           where process.WorkFlowProcessId == allProcessTask.WorkFlowProcessId && process.WorkFlowId == workFlow.WorkFlowId
                                                                           orderby allProcessTask.SequenceCode
                                                                           select allProcessTask).ToList());
                                }
                            }
                        }
                        itsWorkFlowStep.InnerSteps = new List <WorkFlowInnerStepInfo>(itsInnerSteps);
                    }
                    workFlow.Steps.Add(itsWorkFlowStep);
                }
            }
            foreach (var workFlow in workFlows)
            {
                workFlow.EntityId = iMetadataManager.GetEntityNameByEntityContext(workFlow.EntityId);
                var subTypes = iMetadataManager.GetSubTypesDetails(workFlow.EntityId);
                foreach (var subType in subTypes)
                {
                    if (subType.Key == workFlow.SubTypeCode)
                    {
                        workFlow.SubTypeCode = subType.Value;
                    }
                }
            }
            return(workFlows);
        }