Beispiel #1
0
        /// <summary>
        /// method to return the expression condition to filter out those records that are not accessible to position's locations/equipments
        /// </summary>
        /// <param name="currentUserID"></param>
        /// <param name="roleNameCode">role code.</param>
        /// <param name="isLocation"> if this is true, it will be based on location, else equipment</param>
        /// <param name="hierarchyPathColumn">pass in the column to be built condition, forexample, TablesLogic.tContract.Locations.HierarchyPath</param>
        /// <returns></returns>
        public static ExpressionCondition GetAccessibleCondition(string currentUserID, bool isLocation, SchemaString hierarchyPathColumn, params string[] roleNameCode)
        {
            OUser user = TablesLogic.tUser.Load(new Guid(currentUserID));
            List<OPosition> positions = OPosition.GetPositionsByUserByRoleCode(user, roleNameCode);                

            if (positions != null && positions.Count > 0)
            { 
                foreach (OPosition position in positions)
                {
                    if (isLocation)
                    {
                        ExpressionCondition cond = null;
                        foreach (OLocation location in position.LocationAccess)
                        {
                            if (cond == null)
                                cond = hierarchyPathColumn.Like(location.HierarchyPath + "%");
                            else
                                cond = cond | hierarchyPathColumn.Like(location.HierarchyPath + "%");
                        }
                        return cond;
                    }
                    else
                    {
                        ExpressionCondition cond = null;
                        foreach (OEquipment equipment in position.EquipmentAccess)
                        {
                            if (cond == null)
                                cond = hierarchyPathColumn.Like(equipment.HierarchyPath + "%");
                            else
                                cond = cond | hierarchyPathColumn.Like(equipment.HierarchyPath + "%");
                        }
                        return cond;
                    }
                }                                
            }            
            return null;
        }