Exemplo n.º 1
0
        public int AddUserToLevel(WorkflowActorModel model, int workflowLevelId, bool actorMustAlwaysApproveInLevel = false)
        {
          
            var wkLevel = _workflowLevels.Find(workflowLevelId);
            if (wkLevel != null)
            {
                
                if ((bool) !wkLevel.Workflow.DisallowSameUserMultiLevel)
                {
                    var _Existing = _actorsInLevels.Table.Where(x => x.WorkflowActor.ActorRefId == model.ActorRefId &&
                                                     x.WorkflowLevel.WorkflowId == wkLevel.WorkflowId);
                    if (_Existing.Count() > 0)
                        throw new WorkflowConfigurationError("User " + model.Description + " already exist in the Workflow.");

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

                    _actor.Description = model.Description;
                    _actors.Update(_actor);
                    actorId = _actor.Id;

                }
                else
                {
                    Mapper.CreateMap<WorkflowActorModel, WorkflowActor>();
                    var actor = Mapper.Map<WorkflowActorModel, WorkflowActor>(model);
                    actor.ApplicationId = wkLevel.Workflow.ApplicationId;
                    _actors.Insert(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.Insert(_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.Insert(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.");

            }


        }
Exemplo n.º 2
0
        public int AddUserToWorkflowLevel2(WorkflowActorModel model, int WorkflowLevelId, bool ActorMustAlwaysApproveInLevel = false)
        {
            //NHibernateHelper.GetCurrentSession().BeginTransaction();
            var wkLevel = _workflowLevels.Find(WorkflowLevelId);
            if (wkLevel != null)
            {
                //try
                //{
                //    NHibernateHelper.GetCurrentSession().BeginTransaction();
                if ((bool) !wkLevel.Workflow.DisallowSameUserMultiLevel)
                {
                    var _Existing = _actorsInLevels.Table.Where(x => x.WorkflowActor.ActorRefId == model.ActorRefId &&
                                                     x.WorkflowLevel.WorkflowId == wkLevel.WorkflowId);
                    if (_Existing.Count() > 0)
                        throw new WorkflowConfigurationError("User " + model.Description  + " already exist in the Workflow.");

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

                        _actor.Description = model.Description;
                        _actors.Update(_actor);
                        actorId = _actor.Id;

                    }
                    else
                    {
                        Mapper.CreateMap<WorkflowActorModel, WorkflowActor>();
                        var actor = Mapper.Map<WorkflowActorModel, WorkflowActor>(model);
                        actor.ApplicationId = wkLevel.Workflow.ApplicationId;
                        _actors.Insert(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.Insert(_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.WorkflowActor.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.");

            }


        }
Exemplo n.º 3
0
        public int AddUserToWorkflowLevel(WorkflowActorModel model, int workflowLevelId, bool actorMustAlwaysApproveInLevel = false)
        {
            WorkflowActorInLevel _inLevel = null;

            var wkLevel = _workflowLevels.Find(workflowLevelId);
            if (wkLevel != null)
            {
                if ((bool) !wkLevel.Workflow.DisallowSameUserMultiLevel)
                {
                    var _Existing = _actorsInLevels.Table.Where(x => x.WorkflowActor.ActorRefId == model.ActorRefId &&
                                                                     x.WorkflowLevel.WorkflowId == wkLevel.WorkflowId);
                    if (_Existing.Any())
                        throw new WorkflowConfigurationError("User " + model.Description + " already exist in the Workflow.");
                }
                var actorId = 0;
                var _actor = GetActor(model.ActorRefId, model.Id);
                if (_actor != null)
                {
                    _actor.Description = model.Description;
                    _actors.Update(_actor);
                    actorId = _actor.Id;

                }
                else
                {
                    Mapper.CreateMap<WorkflowActorModel, WorkflowActor>();
                    var actor = Mapper.Map<WorkflowActorModel, WorkflowActor>(model);
                    actor.ApplicationId = wkLevel.Workflow.ApplicationId;
                    _actors.Insert(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.Insert(_inLevel);





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

            }

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