예제 #1
0
        public static bool HasAccess(string key, UserRoleNType roleNType)
        {
            Matrix.TryGetValue(key, out Dictionary <string, bool> permissions);

            var permissionKey = roleNType.MakeKey();

            permissions.TryGetValue(permissionKey, out bool hasAccess);

            return(hasAccess);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Dictionary <string, bool> permissions = new Dictionary <string, bool>();

            permissions.Add(PermissionType.CUSTOMER_OWNER.ToString(), true);
            permissions.Add(PermissionType.CUSTOMER_ADMIN.ToString(), true);
            permissions.Add(PermissionType.CUSTOMER_EDITOR.ToString(), true);
            permissions.Add(PermissionType.CUSTOMER_VIEWER.ToString(), false);
            PermissionMatrix.Add(PermissionNames.SetOrderPriority, permissions);

            UserRoleNType userRoleNType = new UserRoleNType
            {
                IsCustomer = false,
                Role       = UserRole.Viewer
            };

            var hasAccess = PermissionMatrix.HasAccess(PermissionNames.SetOrderPriority, userRoleNType);

            Console.WriteLine(hasAccess);
            Console.ReadKey();
        }