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.CurrentLevel ?? 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();
        }
Esempio n. 3
0
 public int UpdateUserInWorkflowLevel(WorkflowActor actor, int workflowLevelId, bool actorMustAlwaysApproveInLevel = false)
 {
     return AddUserToWorkflowLevel(actor, workflowLevelId, actorMustAlwaysApproveInLevel);
 }
Esempio n. 4
0
        public int AddUserToWorkflowLevel2(WorkflowActor actor, int WorkflowLevelId, bool ActorMustAlwaysApproveInLevel = false)
        {
            //NHibernateHelper.GetCurrentSession().BeginTransaction();
            var wkLevel = _workflowLevels.Get(WorkflowLevelId);
            if (wkLevel != null)
            {
                //try
                //{
                //    NHibernateHelper.GetCurrentSession().BeginTransaction();
                if (!wkLevel.Workflow.DisallowSameUserMultiLevel)
                {
                    var _Existing = _actorsInLevels.Table.Where(x => x.Actor.ActorRefId == actor.ActorRefId &&
                                                     x.WorkflowLevel.WorkflowId == wkLevel.WorkflowId);
                    if (_Existing.Count() > 0)
                        throw new WorkflowConfigurationError("User " + actor.Description  + " already exist in the Workflow.");

                }
                var actorId = 0;
                    var _actor = GetActor(actor.ActorRefId, actor.Id);
                    if (_actor != null)
                    {

                        _actor.Description = actor.Description;
                        _actors.Add(_actor);
                        actorId = _actor.Id;

                    }
                    else
                    {

                        actor.ApplicationId = wkLevel.Workflow.ApplicationId;
                        _actors.Add(actor);
                        actorId = actor.Id;

                    }

                    //Save ActorInLevel
                    var _inLevel = GetActorInLevel(actorId, WorkflowLevelId);
                    // var _inLevel = GetActorInLevel(actor.Id, WorkflowLevelId);


                    if (_inLevel == null)
                    {
                        _inLevel = new WorkflowActorInLevel()
                        {
                            WorkflowLevelId = WorkflowLevelId,
                            ActorId = actorId,
                            ActorMustApprove = ActorMustAlwaysApproveInLevel
                        };

                    }
                    else
                        _inLevel.ActorMustApprove = ActorMustAlwaysApproveInLevel;
                    _actorsInLevels.Add(_inLevel);

                    var parametrs =
                        _levelParameters.Table.Where(c => c.WorkflowLevelId == WorkflowLevelId).FirstOrDefault();
                    if (parametrs != null)
                        if (parametrs.MaximumApprovalRequired > 1)
                            return _inLevel.Id;

                    //Build the default Expression
                    var actorsInLevel =
                        _actorsInLevels.Table.Where(x => x.WorkflowLevelId == WorkflowLevelId)
                            .Select(x => x.Actor.ActorRefId.ToString());

                    var _Xpression = new WorkflowExpression();
                    _Xpression.Add(Operator.Operands.OPENED_BRACKET);
                    int count = actorsInLevel.Count();
                    int _count = 0;
                    foreach (string _act in actorsInLevel)
                    {
                        ++_count;

                        _Xpression.Add(Operator.Operands.USER, _act, _inLevel.WorkflowLevel.Workflow.ApplicationId);
                        if (_count != count)
                            _Xpression.Add(Operator.Operands.OR);


                    }
                    _Xpression.Add(Operator.Operands.CLOSED_BRACKET);

                    _Xpression.SaveExpression(WorkflowLevelId, 1);
                    // NHibernateHelper.GetCurrentSession().Transaction.Commit();
                    return _inLevel.Id;
                    //}
                    //catch (Exception ex)
                    //{
                    //    NHibernateHelper.GetCurrentSession().Transaction.Rollback();
                    //    throw new WorkflowGenericError("This User cannot be added to the Workflow level: " + ex.Message);
                    //}
           
            }
            else
            {
                throw new WorkflowConfigurationError("Workflow Level does not exist.");

            }


        }
Esempio n. 5
0
        public int AddUserToLevel(WorkflowActor actor, int workflowLevelId, bool actorMustAlwaysApproveInLevel = false)
        {
          
            var wkLevel = _workflowLevels.Get(workflowLevelId);
            if (wkLevel != null)
            {
                
                if (!wkLevel.Workflow.DisallowSameUserMultiLevel)
                {
                    var _Existing = _actorsInLevels.Table.Where(x => x.Actor.ActorRefId == actor.ActorRefId &&
                                                     x.WorkflowLevel.WorkflowId == wkLevel.WorkflowId);
                    if (_Existing.Count() > 0)
                        throw new WorkflowConfigurationError("User " + actor.Description + " already exist in the Workflow.");

                }
                var actorId = 0;
                var _actor = GetActor(actor.ActorRefId, actor.Id);
                if (_actor != null)
                {

                    _actor.Description = actor.Description;
                    _actors.Add(_actor);
                    actorId = _actor.Id;

                }
                else
                {

                    actor.ApplicationId = wkLevel.Workflow.ApplicationId;
                    _actors.Add(actor);
                    actorId = actor.Id;

                }

                //Save ActorInLevel
                var _inLevel = GetActorInLevel(actorId, workflowLevelId);
                // var _inLevel = GetActorInLevel(actor.Id, WorkflowLevelId);


                if (_inLevel == null)
                {
                    _inLevel = new WorkflowActorInLevel()
                    {
                        WorkflowLevelId = workflowLevelId,
                        ActorId = actorId,
                        ActorMustApprove = actorMustAlwaysApproveInLevel
                    };

                }
                else
                    _inLevel.ActorMustApprove = actorMustAlwaysApproveInLevel;
                _actorsInLevels.Add(_inLevel);

                //1. Get the level Expression
                //2. if null, build a new one with a OR
                //3. If not null, Or d new actor to it.

                var parametrs =
                    _levelParameters.Table.Where(c => c.WorkflowLevelId == workflowLevelId).FirstOrDefault();
                if (parametrs == null)
                {

                    var _Xpression = new WorkflowExpression();
                    _Xpression.Add(Operator.Operands.OPENED_BRACKET);

                    _Xpression.Add(Operator.Operands.USER, _actor.ActorRefId, _inLevel.WorkflowLevel.Workflow.ApplicationId);

                    _Xpression.Add(Operator.Operands.CLOSED_BRACKET);

                    _Xpression.SaveExpression(workflowLevelId, 1);

                    return _inLevel.Id; 
                }
                else
                {
                    if (!string.IsNullOrEmpty(parametrs.Expression.Trim()))
                    {
                        var _exp = parametrs.Expression;
                        var _Xpression = new WorkflowExpression();
                        _Xpression.Add(Operator.Operands.OR);

                        _Xpression.Add(Operator.Operands.OPENED_BRACKET);

                        _Xpression.Add(Operator.Operands.USER, _actor.ActorRefId,
                            _inLevel.WorkflowLevel.Workflow.ApplicationId);

                        _Xpression.Add(Operator.Operands.CLOSED_BRACKET);

                        parametrs.Expression = parametrs.Expression + " " + _Xpression.GetRawLogicalExpresion();
                        parametrs.Parameters = parametrs.Parameters + " " + _Xpression.GetViewerLogicalExpresion();
                        _levelParameters.Add(parametrs);
                        return _inLevel.Id;
                    }
                    else
                    {
                        return _inLevel.Id;
                    }
                }

                //if (parametrs != null)
                //    if (parametrs.MaximumApprovalRequired > 1)
                //        return _inLevel.Id;

                ////Build the default Expression
                //var actorsInLevel =
                //    _actorsInLevels.Table.Where(x => x.WorkflowLevelId == WorkflowLevelId)
                //        .Select(x => x.Actor.ActorRefId.ToString());

                //var _Xpression = new WorkflowExpression();
                //_Xpression.Add(Operator.Operands.OPENED_BRACKET);
                //int count = actorsInLevel.Count();
                //int _count = 0;
                //foreach (string _act in actorsInLevel)
                //{
                //    ++_count;

                //    _Xpression.Add(Operator.Operands.USER, _act, _inLevel.WorkflowLevel.Workflow.ApplicationId);
                //    if (_count != count)
                //        _Xpression.Add(Operator.Operands.OR);


                //}
                //_Xpression.Add(Operator.Operands.CLOSED_BRACKET);

                //_Xpression.SaveExpression(WorkflowLevelId, 1);
               
              
           

            }
            else
            {
                throw new WorkflowConfigurationError("Workflow Level does not exist.");

            }


        }
Esempio n. 6
0
        public int AddUserToWorkflowLevel(WorkflowActor actor, int workflowLevelId, bool actorMustAlwaysApproveInLevel = false)
        {
            WorkflowActorInLevel _inLevel = null;

            var wkLevel = _workflowLevels.Get(workflowLevelId);
            if (wkLevel != null)
            {

                if (!wkLevel.Workflow.DisallowSameUserMultiLevel)
                {
                    var _Existing = _actorsInLevels.Table.Where(x => x.Actor.ActorRefId == actor.ActorRefId &&
                                                     x.WorkflowLevel.WorkflowId == wkLevel.WorkflowId);
                    if (_Existing.Any())
                        throw new WorkflowConfigurationError("User " + actor.Description + " already exist in the Workflow.");

                }
                var actorId = 0;
                var _actor = GetActor(actor.ActorRefId, actor.Id);
                if (_actor != null)
                {

                    _actor.Description = actor.Description;
                    _actors.Add(_actor);
                    actorId = _actor.Id;

                }
                else
                {

                    actor.ApplicationId = wkLevel.Workflow.ApplicationId;
                    _actors.Add(actor);
                    actorId = actor.Id;

                }

                //Save ActorInLevel
                 _inLevel = GetActorInLevel(actorId, workflowLevelId);
                // var _inLevel = GetActorInLevel(actor.Id, WorkflowLevelId);


                if (_inLevel == null)
                {
                    _inLevel = new WorkflowActorInLevel()
                    {
                        WorkflowLevelId = workflowLevelId,
                        ActorId = actorId,
                        ActorMustApprove = actorMustAlwaysApproveInLevel
                    };

                }
                else
                    _inLevel.ActorMustApprove = actorMustAlwaysApproveInLevel;
                _actorsInLevels.Add(_inLevel);





            }
            else
            {
                throw new WorkflowConfigurationError("Workflow Level does not exist.");

            }

            return _inLevel == null ? 0 :_inLevel.Id;
        }