Esempio n. 1
0
        // Method SetRolesForForm
        public static void SetRoleForMenu(this MenuStrip menu)
        {
            if (GlobalConstants.RoleName != Admin)
            {
                ManipulationRoleModel maniModel = Roles.Where(p => p.Manipulation.Equals(EnumRoles.AllRoles.GetControlName())).FirstOrDefault();

                ToolStripItem item = menu.Items.Cast <ToolStripItem>().Where(p => p.Name.Equals(MenuRoles)).FirstOrDefault();

                menu.Items.Remove(item);

                if (maniModel == null)
                {
                    for (int i = 0; i < menu.Items.Count; i++)
                    {
                        ManipulationRoleModel manipulationModel = Roles.Where(p => p.Manipulation.Equals(menu.Items[i].Name)).FirstOrDefault();

                        if (manipulationModel == null)
                        {
                            menu.Items.RemoveAt(i);

                            i--;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        // Method SetRolesShowLogs
        public static bool SetRolesShowLogs()
        {
            if (GlobalConstants.RoleName != Admin)
            {
                ManipulationRoleModel maniModel = Roles.Where(p => p.Manipulation.Equals(EnumRoles.AllRoles.GetControlName())).FirstOrDefault();

                if (maniModel == null)
                {
                    return(Roles.Where(p => p.Manipulation.Equals(EnumRoles.ShowLogs.GetControlName())).FirstOrDefault() != null);
                }
            }

            return(true);
        }
Esempio n. 3
0
        // Method SetRoleForUserControl
        public static void SetRoleForTableLayout(this TableLayoutPanel layout)
        {
            if (GlobalConstants.RoleName != Admin)
            {
                foreach (Control c in layout.Controls)
                {
                    MetroButton button = c as MetroButton;

                    if (button != null)
                    {
                        ManipulationRoleModel manipulationModel = Roles.Where(p => p.Manipulation.Equals(button.Name)).FirstOrDefault();

                        if (manipulationModel == null)
                        {
                            button.Enabled = false;
                        }
                    }
                }
            }
        }