Ejemplo n.º 1
0
        //  [CustomAuthorize]
        public async Task <dynamic> LoadMenuSetupData(string ownerID)
        {
            List <Parent> parent = new List <Parent>();
            List <Child>  child  = new List <Child>();
            List <SEC_NavMenuOptSetup> resultNav = null;
            var data = await Task.Run(() => _menuSetupService.GetNavMenuOptSetup(ownerID, out resultNav));

            var root = (from t in resultNav where t.ParentMenuID == "0" select t).ToList();

            foreach (var item in root)
            {
                Model.SecurityModule.Parent p = new Model.SecurityModule.Parent();
                p.key      = item.MenuID;
                p.title    = item.MenuTitle;
                p.isFolder = true;
                child      = GetChild(resultNav, item.MenuID);
                //  p.select = Convert.ToBoolean(item.check == "" ? "false" : item.check);

                if (child.Count > 0)
                {
                    p.children = child;
                }
                parent.Add(p);
            }

            return(Json(parent, JsonRequestBehavior.AllowGet));
        }
        public async Task <dynamic> GetMenuTreeData(string _OwnerID)
        {
            List <SEC_User> users = null;
            await Task.Run(() => _userService.GetAllUser(UserID, "", out users));

            var roleInfo = (from r in users
                            where r.UserID == UserID
                            select new
            {
                RoleID = r.RoleID,
                RoleTitle = r.RoleTitle
            }).FirstOrDefault();

            if (roleInfo.RoleTitle == "Super Admin")
            {
                List <Model.SecurityModule.Parent> parent = new List <Model.SecurityModule.Parent>();
                List <Child> child = new List <Child>();
                List <SEC_NavMenuOptSetup> resultNav = null;
                await Task.Run(() => _roleMenuPermissionService.GetOwnerPermittedMenu
                                   (UserID, "", out resultNav));

                var root = (from t in resultNav where t.ParentMenuID == "0" &
                            t.Status == 1 select t).ToList();
                foreach (var item in root)
                {
                    Model.SecurityModule.Parent p = new Model.SecurityModule.Parent();
                    p.key   = item.MenuID;
                    p.title = item.MenuTitle;
                    child   = GetChild(resultNav, item.MenuID);
                    if (child.Count > 0)
                    {
                        p.children = child;
                    }
                    parent.Add(p);
                }

                return(Json(parent, JsonRequestBehavior.AllowGet));
            }
            else
            {
                List <SEC_RoleMenuPermission> roleMenuPermissionList = null;
                await Task.Run(() => _roleMenuPermissionService.
                               GetRoleMenuPermission(UserID, "", out roleMenuPermissionList));

                List <SEC_NavMenuOptSetup> resultNav = null;
                await Task.Run(() => _roleMenuPermissionService.GetOwnerPermittedMenu
                                   (UserID, "", out resultNav));


                var PermittedMenus = (from pm in roleMenuPermissionList
                                      where pm.RoleID == roleInfo.RoleID & pm.Status == 1
                                      join m in resultNav on pm.MenuID equals m.MenuID into permittedmenus
                                      from r in permittedmenus.DefaultIfEmpty()
                                      select new SEC_NavMenuOptSetup
                {
                    MenuID = pm.MenuID,
                    MenuTitle = pm.MenuTitle,
                    MenuUrl = r.MenuUrl,
                    ParentMenuID = r.ParentMenuID,
                    MenuIcon = r.MenuIcon,
                    MenuOrder = r.MenuOrder,
                    SetBy = pm.SetBy,
                    SetOn = pm.SetOn,
                    Status = pm.Status
                }).ToList();


                List <Model.SecurityModule.Parent> parent = new List <Model.SecurityModule.Parent>();
                List <Child> child = new List <Child>();


                var root = (from t in PermittedMenus where t.ParentMenuID == "0" &
                            t.Status == 1 select t).ToList();
                foreach (var item in root)
                {
                    Model.SecurityModule.Parent p = new Model.SecurityModule.Parent();
                    p.key   = item.MenuID;
                    p.title = item.MenuTitle;
                    child   = GetChild(PermittedMenus, item.MenuID);
                    if (child.Count > 0)
                    {
                        p.children = child;
                    }
                    parent.Add(p);
                }

                return(Json(parent, JsonRequestBehavior.AllowGet));
            }
        }