Пример #1
0
        //public ActionResult List()
        //{
        //    if (null == Session[this.SESSION_NAME_USERID])
        //    {
        //        return RedirectToAction("Login", "Home");
        //    }
        //    if (Session["IsAdmin"] is false)
        //    {
        //        return RedirectToAction("Logout", "Home");
        //    }
        //    this.SetCommonData();
        //    ViewData["pagename"] = "menu_list";
        //    ViewData["action_block"] = "Menus/block_menu_list";


        //    this.GetLanguage();
        //    ViewData["VIEWDATA_LANGUAGE"] = this.LANGUAGE_OBJECT;


        //    BlockMenuListLangModel blockLang = new BlockMenuListLangModel();
        //    BI_Project.Models.UI.BlockModel blockModel = new Models.UI.BlockModel("block_menu_list", this.LANGUAGE_OBJECT, blockLang);
        //    //blockModel.DataModel = ViewData["block_menu_left_data"];
        //    blockModel.Hidden = 0;
        //    ViewData["BlockData"] = blockModel;
        //    return View("~/" + this.THEME_FOLDER + "/" + this.THEME_ACTIVE + "/index.cshtml");
        //}

        //lIST


        public ActionResult List(int?DeptID = null, int?userId = null, int?roleId = null)
        {
            if (Session["IsAdmin"] is false)
            {
                return(RedirectToAction("Logout", "Home"));
            }
            var _deptID = (int)Session["DepartIdUserLogin"];

            //DeptID = (int)Session["DepartIdUserLogin"];
            if (DeptID == null)
            {
                DeptID = _deptID;
            }

            //CheckAdminPermission();
            SetCommonData();
            MenuServices menuServices = new MenuServices(DBConnection);

            if (!Request.IsAjaxRequest())
            {
                if (null == Session[SESSION_NAME_USERID])
                {
                    return(RedirectToAction("Login", "Home"));
                }
                if (Session["IsAdmin"] is false)
                {
                    return(RedirectToAction("Logout", "Home"));
                }

                ViewData["pagename"]     = "menu_list";
                ViewData["action_block"] = "Menus/block_menu_list";

                GetLanguage();
                ViewData["VIEWDATA_LANGUAGE"] = LANGUAGE_OBJECT;

                BlockMenuListLangModel blockLang  = new BlockMenuListLangModel();
                BlockModel             blockModel = new BlockModel("block_menu_list", LANGUAGE_OBJECT, blockLang);
                Services.Departments.DepartmentServices departmentServices = new Services.Departments.DepartmentServices(this.DBConnection);

                ViewData["departments"]          = departmentServices.GetList();
                ViewData["listdepartmentsadmin"] = departmentServices.GetListAdminLogin((string)Session["CodeIsAdmin"]);



                ViewData["BlockData"] = blockModel;

                SetConnectionDB();

                var menuData = menuServices.GetMenusByDepId((int)Session[SESSION_NAME_USERID], DeptID);
                ViewData["CurrentOrgId"] = DeptID;
                ViewData["MenuData"]     = menuData;

                return(View("~/" + THEME_FOLDER + "/" + THEME_ACTIVE + "/index.cshtml"));
            }
            else
            {
                var menuData = menuServices.GetMenusByDepId((int)Session[SESSION_NAME_USERID], DeptID);
                // lấy danh sách quyền
                if (userId != null)
                {
                    var menuUserData = menuServices.GetUserMenusByUserId(userId.Value);
                    foreach (var item in menuData)
                    {
                        var inttt = menuUserData.IndexOf(item.MenuId);
                        if (menuUserData.IndexOf(item.MenuId) != -1)
                        {
                            item.Selected = true;
                        }
                        else
                        {
                            item.Selected = false;
                        }
                    }
                }
                else if (roleId != null)
                {
                    var menuUserData = menuServices.GetRoleMenusByRoleId(roleId.Value);
                    foreach (var item in menuData)
                    {
                        if (menuUserData.IndexOf(item.MenuId) != -1)
                        {
                            item.Selected = true;
                        }
                        else
                        {
                            item.Selected = false;
                        }
                    }
                }

                var uiMenuTreeHelper = new UIMenuTreeHelper(menuData);
                var uiMenuDataJson   = uiMenuTreeHelper.BuildMenuToJsonStr(uiMenuTreeHelper.RootId);
                return(Json((new JavaScriptSerializer()).Deserialize(uiMenuDataJson, typeof(object)), JsonRequestBehavior.AllowGet));
            }
        }