Ejemplo n.º 1
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.");

            }


        }
Ejemplo n.º 2
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.");

            }


        }