Beispiel #1
0
        public async Task <List <NewProcessTypeList> > ReturnProcessTypeList(SipUser CurrentUser)
        {
            List <NewProcessTypeList> ProcesstypeList = new List <NewProcessTypeList>();
            var TemplateIdFlowIds = await _processProvider.CreateGetInitialTemplateFlowList();

            foreach (var TemplateIdFlowId in TemplateIdFlowIds)
            {
                string From = "DECLARE @LanguageId int; SELECT @LanguageId = IntPreference FROM UserPreferences WHERE USerId = '" + CurrentUser.Id + "' AND UserPreferences.PreferenceTypeId = 1 ;" +
                              " SELECT  ProcessTypeFlowConditions.ProcessTypeID , ProcessTypeGroupID, ISNULL(UserLanguage.Name,ISNULL(DefaultLanguage.Name,'No name for this classification')) Name, TRIM(Icons.FileName) FileName FROM ProcessTypeFlowConditions" +
                              " JOIN ProcessTypes ON ProcessTypeFlowConditions.ProcessTypeId = ProcessTypes.ProcessTypeId " +
                              " JOIN Icons ON ICons.IconId = ProcessTypes.IconId " +
                              " LEFT JOIN(SELECT ProcessTypeId, Name FROM ProcessTypeLanguages WHERE LanguageId = @LanguageID) UserLanguage " +
                              "  ON UserLanguage.ProcessTypeID = ProcessTypeFlowConditions.ProcessTypeID " +
                              "LEFT JOIN(SELECT ProcessTypeId, Name FROM ProcessTypeLanguages JOIN Settings ON ProcessTypeLanguages.LanguageId = Settings.IntValue WHERE Settings.SettingId = 1) DefaultLanguage " +
                              "  ON DefaultLanguage.ProcessTypeID = ProcessTypeFlowConditions.ProcessTypeID ";
                string Where      = " WHERE ProcessTypeFlowId = " + TemplateIdFlowId.ProcessTypeFlowId + " AND ";
                var    Conditions = await _processProvider.CreateGetInitialTemplateFlowConditionList(TemplateIdFlowId.ProcessTypeFlowId);

                foreach (var Condition in Conditions)
                {
                    if (Condition.ProcessTypeFlowConditionTypeId == 1) //Creator is user
                    {
                        //                    From = From + NewProcess. '  '
                        //Have to check if this can be used in general or only new processes
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 2) //  Field
                    {
                        //NOT RELEVANT FOR NEW PROCESS
                        //if (!new[] { 1, 2, 12, 13, 30, 31, 32 }.Contains(Condition.Fie.ProcessTypeFieldTypeId))
                        //{
                        //    Where = Where + " 1=2 ";
                        //}
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 3) //  Security level user
                    {
                        var UserSecurityLevel = await _userProvider.UserSecurityLevel(CurrentUser.Id);

                        if (Condition.ComparisonOperatorId == 1)  //Comparison blank
                        {
                            Where = Where + " 1=1 ";
                        }
                        if (Condition.ComparisonOperatorId == 2 && UserSecurityLevel != Condition.StageFieldIntValue) //Equal
                        {
                            Where = Where + UserSecurityLevel.ToString() + " =  " + Condition.ProcessTypeFlowConditionInt.ToString();
                        }
                        if (Condition.ComparisonOperatorId == 3 && UserSecurityLevel <= Condition.StageFieldIntValue) // >
                        {
                            Where = Where + UserSecurityLevel.ToString() + " > " + Condition.ProcessTypeFlowConditionInt.ToString();
                        }
                        if (Condition.ComparisonOperatorId == 4 && UserSecurityLevel >= Condition.StageFieldIntValue) //<
                        {
                            Where = Where + UserSecurityLevel.ToString() + " <  " + Condition.ProcessTypeFlowConditionInt.ToString();
                        }
                        if (Condition.ComparisonOperatorId == 5 && UserSecurityLevel < Condition.StageFieldIntValue) //>=
                        {
                            Where = Where + UserSecurityLevel.ToString() + " >=  " + Condition.ProcessTypeFlowConditionInt.ToString();
                        }
                        if (Condition.ComparisonOperatorId == 6 && UserSecurityLevel > Condition.StageFieldIntValue) //<=
                        {
                            Where = Where + UserSecurityLevel.ToString() + " <=  " + Condition.ProcessTypeFlowConditionInt.ToString();
                        }
                        if (Condition.ComparisonOperatorId == 7 && UserSecurityLevel == Condition.StageFieldIntValue) //<>
                        {
                            Where = Where + UserSecurityLevel.ToString() + " <> " + Condition.ProcessTypeFlowConditionInt.ToString();
                        }
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 4) // Role user
                    {
                        var Roles = await _userProvider.RoleIdForSpecificUser(CurrentUser.Id);

                        for (int i = 0; i < Roles.Count; i++)
                        {
                            Roles[i] = Roles[i].Replace("\t", "");
                        }
                        if (!Roles.Contains(Condition.ProcessTypeFlowConditionString.Replace("\t", "")))
                        {
                            Where = Where + " 14=2 ";
                        }
                    }
                    //PETER not sure yet
                    if (Condition.ProcessTypeFlowConditionTypeId == 5) //  Manager user field
                    {
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 6) //  Organization user
                    {
                        var Organizations = await _userProvider.UserOrganizations(CurrentUser.Id);

                        if (!Organizations.Contains(Condition.ProcessTypeFlowConditionInt))
                        {
                            Where = Where + " 1=42 ";
                        }
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 7) //  Organization role user
                    {
                        var RoleId        = Condition.ProcessTypeFlowConditionString;
                        var Organizations = await _userProvider.UserRoleOrganizations(CurrentUser.Id, RoleId);

                        if (!Organizations.Contains(Condition.ProcessTypeFlowConditionInt))
                        {
                            Where = Where + " 1=25 ";
                        }
                    }
                    //PETER TODO
                    if (Condition.ProcessTypeFlowConditionTypeId == 8) //  Organization parent user
                    {
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 9) //  Organization parent role user
                    {
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 10) // Project user
                    {
                        var Projects = await _userProvider.UserProjects(CurrentUser.Id);

                        if (!Projects.Contains(Condition.ProcessTypeFlowConditionInt))
                        {
                            Where = Where + " 1=26 ";
                        }
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 11) //Project role user
                    {
                        var RoleId   = Condition.ProcessTypeFlowConditionString;
                        var Projects = await _userProvider.UserRoleProjects(CurrentUser.Id, RoleId);

                        if (!Projects.Contains(Condition.ProcessTypeFlowConditionInt))
                        {
                            Where = Where + " 1=27 ";
                        }
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 12) //Project parent user
                    {
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 13) //Project parent role user
                    {
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 14) //Default organization user
                    {
                        var Organization = await _userProvider.UserDefaultOrganization(CurrentUser.Id);

                        if (Organization != Condition.ProcessTypeFlowConditionInt)
                        {
                            Where = Where + " 1=28 ";
                        }
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 15) //Open bracket
                    {
                        Where = Where + " ( ";
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 16) //and
                    {
                        Where = Where + " AND ";
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 17) //or
                    {
                        Where = Where + " OR ";
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 18) //Close bracket
                    {
                        Where = Where + " ) ";
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 19) //User
                    {
                        if (CurrentUser.Id != Condition.ProcessTypeFlowConditionString)
                        {
                            Where = Where + " 1=29 ";
                        }
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 20) //Relation to creator
                    {
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 21) //Relation to user field
                    {
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 22) //Classification relation
                    {
                    }
                    if (Condition.ProcessTypeFlowConditionTypeId == 23) //Classification relation type
                    {
                    }
                }
                if (Where == " WHERE ProcessTypeFlowId = " + TemplateIdFlowId.ProcessTypeFlowId + " AND ")
                {
                    Where = " WHERE ProcessTypeFlowId = " + TemplateIdFlowId.ProcessTypeFlowId;
                }
                if (!ProcesstypeList.Any(t => t.ProcessTypeId == TemplateIdFlowId.ProcessTypeId))
                {
                    var y = await _frontProcessProvider.CreateGetTemplateList(From + Where);

                    if (y.Count != 0)
                    {
                        var z = y.First();
                        z.FileName = "/images/icons/" + z.FileName;
                        ProcesstypeList.Add(z);
                    }
                }
            }
            return(ProcesstypeList);
        }