Exemplo n.º 1
0
        private void AddChidrenNode(ref AuthMenuViewModel node, List<Auth_Menu> allAuthMenu, List<Auth_Menu> listAction)
        {
            try
            {
                string parentID = node.id;
                var obj = listAction.Find(p => p.MenuID == parentID);
                if(obj != null)
                {
                    node.@checked = true;
                }
                List<Auth_Menu> lstChildMenu = allAuthMenu.Where(p => p.ParentMenuID == parentID).ToList();// db.Select<Auth_Menu>("IsVisible = {0} AND ParentMenuID ={1}", true, parentID).OrderBy(p => p.MenuIndex).ToList();//Danh sách menu con của parentID
                foreach (Auth_Menu der in lstChildMenu)
                {
                    AuthMenuViewModel n = new AuthMenuViewModel();
                    n.id = der.MenuID;
                    n.text = der.MenuName;

                    var check = listAction.Find(p => p.MenuID == der.MenuID);
                    if (check != null)
                    {
                        n.@checked = true;
                    }

                    n.items = new List<AuthMenuViewModel>();
                    AddChidrenNode(ref n, allAuthMenu, listAction);
                    node.items.Add(n);
                }
            }
            catch (Exception)
            {

            }
        }
Exemplo n.º 2
0
        //public JsonResult GetMenu([DataSourceRequest] DataSourceRequest request)
        //{
        //    IDbConnection db = new OrmliteConnection().openConn();
        //    try
        //    {
        //        var listMenu = db.Select<Auth_Menu>(p => p.IsVisible == true).OrderBy(p => p.MenuIndex).ToList();
        //        DataSourceResult dsr = new DataSourceResult();
        //        dsr.Data = listMenu;
        //        return Json(dsr, JsonRequestBehavior.AllowGet);
        //    }
        //    catch (Exception e)
        //    {
        //        return Json(new { success = false, message = e.Message });
        //    }
        //    finally { db.Close(); }
        //}
        //[HttpPost]
        public JsonResult GetMenu(string action, int roleID)
        {
            IDbConnection db = new OrmliteConnection().openConn();
            try
            {
                //select list menu cha
                List<Auth_Menu> lstFirstMenu = db.Select<Auth_Menu>("IsVisible = 1 AND ParentMenuID ='' AND MenuID <> 'Home'").OrderBy(p => p.MenuIndex).ToList();
                List<Auth_Menu> allAuthMenu = db.Select<Auth_Menu>("IsVisible = 1  AND MenuID <> 'Home'").OrderBy(p => p.MenuIndex).ToList();

                var listAction = new List<Auth_Menu>();
                if (!string.IsNullOrEmpty(action))
                {
                    listAction = db.SqlList<Auth_Menu>("p_Auth_Menu_Select_By_Action '" + action + "', " + roleID);
                }

                List<AuthMenuViewModel> lstMenuView = new List<AuthMenuViewModel>();
                foreach (Auth_Menu der in lstFirstMenu)
                {
                    AuthMenuViewModel node = new AuthMenuViewModel();
                    node.id = der.MenuID;
                    node.text = der.MenuName;
                    node.items = new List<AuthMenuViewModel>();
                    AddChidrenNode(ref node, allAuthMenu,listAction);
                    lstMenuView.Add(node);
                }
                return Json(new { success = true, Data = lstMenuView });
            }
            catch (Exception e)
            {
                return Json(new { success = false, message = e.Message });
            }
            finally { db.Close(); }
        }