Exemplo n.º 1
0
        public IList <MenuAccessRoleDTO> GetRolePermission(int RoleID)
        {
            try
            {
                List <MenuAccessRoleDTO> menuList = new List <MenuAccessRoleDTO>();
                IList <Menu>             menus    = _menuRepository.GetMenu().Where(x => x.RoleAccessList.Any(y => y.Role.Id == RoleID)).ToList();

                if (menus != null && menus.Count > 0)
                {
                    menuList = MenuAccessRoleDTO.From(menus, true).ToList();
                }
                menus = _menuRepository.GetMenu().Where(x => !x.RoleAccessList.Any(y => y.Role.Id == RoleID)).ToList();
                if (menus != null && menus.Count > 0)
                {
                    menuList.AddRange(MenuAccessRoleDTO.From(menus, false).ToList());
                }
                var mn = BuildTreeNew(menuList);
                return(mn.OrderBy(x => x.Id)
                       .ThenBy(x => x.Sequence)
                       .ThenByDescending(x => x.IsOnMenu)
                       .ThenBy(x => x.ControllerName)
                       .ThenBy(x => x.Name)
                       .ToList());
            }
            catch (Exception x)
            {
                throw x;
            }
        }
Exemplo n.º 2
0
        public IList <MenuAccessRoleDTO> BuildTreeNew(IList <MenuAccessRoleDTO> source)
        {
            try
            {
                var menuExceptMainMenu          = source.Where(x => x.Name != "Main Menu").ToList();
                IList <MenuAccessRoleDTO> roots = menuExceptMainMenu.Where(x => x.ParentId < 1).ToList();

                IList <MenuAccessRoleDTO> rootsDTO = new List <MenuAccessRoleDTO>();
                if (roots.Count > 0)
                {
                    var nonroots = menuExceptMainMenu.Except(roots).ToList();
                    for (int i = 0; i < roots.Count; i++)
                    {
                        MenuAccessRoleDTO rootDTO = MenuAccessRoleDTO.From(roots[i]);
                        AddChildrenNew(rootDTO, nonroots);
                        rootsDTO.Add(rootDTO);
                    }
                }

                return(rootsDTO);
            }
            catch (Exception x)
            {
                throw x;
            }
        }
Exemplo n.º 3
0
        public IList <MenuAccessRoleDTO> GetAllDifferentiateByRole(int RoleID)
        {
            try
            {
                List <MenuAccessRoleDTO> menuList = new List <MenuAccessRoleDTO>();
                IList <Menu>             menus    = _menuRepository.GetMenu().Where(x => x.RoleAccessList.Any(y => y.Role.Id == RoleID)).ToList();
                if (menus != null && menus.Count > 0)
                {
                    menuList = MenuAccessRoleDTO.From(menus, true).ToList();
                }
                menus = _menuRepository.GetMenu().Where(x => !x.RoleAccessList.Any(y => y.Role.Id == RoleID)).ToList();
                if (menus != null && menus.Count > 0)
                {
                    menuList.AddRange(MenuAccessRoleDTO.From(menus, false).ToList());
                }

                var menuExceptMainMenu = menuList.Where(x => x.ControllerName != "Main").ToList();
                return(menuExceptMainMenu);
            }
            catch (Exception x)
            {
                throw x;
            }
        }