Esempio n. 1
0
        private bool CanUserApproveHelper(WorkflowActor actor, WorkflowProcess process, int workflowLevelId = -1)
        {
            //var actor = _actors.Table.FirstOrDefault(x => x.ActorRefId == userRefId.ToString());
            //var process = _processes.Table.FirstOrDefault(x => x.ProcessRefId == processRefId.ToString());
            if (actor == null || process == null) return false;
            if (process.Closed)
                return false;

            var currentLevel = process.WorkflowLevel ?? GetWorkflowLevel(process.CurrentLevelId);
            if (currentLevel == null) return false;
            var actorInLevel = _actorsInLevels.Table.FirstOrDefault(x => x.WorkflowLevelId == currentLevel.Id
                                                                         && x.ActorId == actor.Id);
            if (actorInLevel == null) return false;
            var hasUserApproved = HasUserApproved(actor, process, workflowLevelId: currentLevel.Id);

            if (hasUserApproved) return false; //not approved before

            // var _Xpression = _levelParameters.Table.Where(x => x.WorkflowLevelId == currentLevel.Id).FirstOrDefault();
            var approvalHistory = _histories.Table.Where(x => x.Approved && x.LevelId == currentLevel.Id
                                                              && x.ProcessId == process.Id);

            //TO DO . . .
            //one of the actors in this current level must hv approved, just for confirmation, they may hv changed the workflow . . .

            //var _actorsInLevel = GetUsersInLevel(currentLevel.Id).Select(x=>x.Id);
            // approvalHistory = approvalHistory.Where(x => _actorsInLevel.Contains(x.ActorId));

            //We may need to uncomment this later . . .
            if (currentLevel.MaximumApprovalRequired > 0)
                return approvalHistory.Count() != currentLevel.MaximumApprovalRequired;
            //var actorsInLevel = GetUsersInLevel(currentLevel.Id);
            //if (actorsInLevel.Count() < currentLevel.MaximumApprovalRequired)
            //    throw new WorkflowConfigurationError("The Maximum Allowable Approval for Workflow Level: " + currentLevel.Name + " is " + currentLevel.MaximumApprovalRequired + ". Only a total number of " + actorsInLevel.Count() + " Actors, which is less, can be found.");
            return true; //approvalHistory.Count() != currentLevel.MaximumApprovalRequired;
        }
Esempio n. 2
0
        public bool HasUserApproved(WorkflowActor actor, WorkflowProcess process, 
            int workflowId = -1, string workflowName = "", int workflowLevelId = -1)
        {
            //_actors.Table.FirstOrDefault(x => x.ActorRefId == userRefId.ToString());
            //var process = _processes.Table.FirstOrDefault(x => x.ProcessRefId == processRefId.ToString());
            if (actor == null || process == null) return false;
            var userRefId = actor.ActorRefId;
            var processRefId = process.ProcessRefId;
            if (workflowLevelId > 0)
            {
                var hst = GetAllUserApprovals(userRefId, processRefId).Where(x => x.Approved && x.LevelId == workflowLevelId);
                return hst.Any();
            }
            if (workflowId > 0)
            {
                var hst = GetAllUserApprovals(userRefId, processRefId).Where(x => x.Approved && x.WorkflowLevel.WorkflowId == workflowId);

                return hst.Any();
            }
            if (!string.IsNullOrEmpty(workflowName))
            {
                var hst = GetAllUserApprovals(userRefId, processRefId).Where(x => x.Approved && x.WorkflowLevel.Workflow.Name.ToLower() == workflowName.ToLower());

                return hst.Any();
            }
            var hstory = GetAllUserApprovals(userRefId, processRefId).Where(x => x.Approved);

            return hstory.Any();
        }