Exemplo n.º 1
0
        public ContentResult MenusToAdd(B_Menu menu)
        {
            menu.IsShow  = Request["IsShow"] != null && Request["IsShow"].ToString() == "on" ? true : false;
            menu.IsValid = Request["IsValid"] != null && Request["IsValid"].ToString() == "on" ? true : false;
            menu.IsRobot = Request["IsRobot"] != null && Request["IsRobot"].ToString() == "on" ? false : true;

            if (string.IsNullOrWhiteSpace(menu.MenuName))
            {
                return(Content("名称不能为空"));
            }
            if (RepeatHelper.NoRepeat("B_Menu", "MenuName", menu.MenuName, menu.ID) > 0)
            {
                return(Content("菜单名已存在"));
            }
            if (!string.IsNullOrWhiteSpace(menu.MenuUrl) && RepeatHelper.NoRepeat("B_Menu", "MenuUrl", menu.MenuUrl, menu.ID) > 0)
            {
                return(Content("菜单链接已存在"));
            }

            int rtn = menu.InsertAndReturnIdentity();

            if (rtn > 0)
            {
                bool hasMainMenuTag          = false;
                bool hasError                = false;
                List <B_MenuRights> muRights = null;
                if (string.IsNullOrWhiteSpace(menu.MenuUrl) == false)
                {
                    menu.MenuUrl = menu.MenuUrl.Trim().TrimEnd('/');
                    try
                    {
                        string[] arrUrl = menu.MenuUrl.TrimStart('/').Split('/');
                        Type     type   = Type.GetType("WeBusiness.Controllers." + arrUrl[0] + "Controller");
                        muRights = BaseAuthorizeHelper.GetBOMenuRightsByControllerType(type, arrUrl[1], out hasMainMenuTag);
                    }
                    catch (Exception ex)
                    {
                        DAL.Log.Instance.Write(ex.ToString(), "BOMenu_Add");
                        hasError = true;
                    }
                }

                if (hasMainMenuTag && muRights != null)
                {
                    B_MenuRights.RelevanceList(rtn, muRights);
                }
                if (hasError)
                {
                    return(Content("添加菜单成功,但菜单没有添加权限!"));
                }


                return(Content("ok"));
            }
            return(Content("添加出错"));
        }
Exemplo n.º 2
0
 public ContentResult UpdateAllRights()
 {
     try
     {
         List <B_Menu> menus    = B_Menu.GetEntitysAll();
         string        ErrorStr = "";
         foreach (B_Menu menu in menus)
         {
             if (menu.ParentID == 0)
             {
                 continue;
             }
             bool hasMainMenuTag          = false;
             List <B_MenuRights> muRights = null;
             if (string.IsNullOrWhiteSpace(menu.MenuUrl) == false)
             {
                 menu.MenuUrl = menu.MenuUrl.Trim().TrimEnd('/');
                 try
                 {
                     string   tmpUrl = menu.MenuUrl.TrimStart('/').Split('?')[0];
                     string[] arrUrl = tmpUrl.Split('/');
                     Type     type   = Type.GetType("WeBusiness.Controllers." + arrUrl[0] + "Controller");
                     muRights = BaseAuthorizeHelper.GetBOMenuRightsByControllerType(type, arrUrl[1], out hasMainMenuTag);
                 }
                 catch (Exception ex)
                 {
                     DAL.Log.Instance.Write(ex.ToString(), "BOMenu_Update");
                     ErrorStr += "【" + menu.MenuName + "】";
                 }
             }
             if (hasMainMenuTag && muRights != null)
             {
                 B_MenuRights.RelevanceList(menu.ID, muRights);
             }
             B_MenuRights.ClearHashMenuRights();
         }
         if (!string.IsNullOrWhiteSpace(ErrorStr))
         {
             return(Content("更新失败的菜单:" + ErrorStr));
         }
         return(Content("ok"));
     }
     catch (Exception ex)
     {
         DAL.Log.Instance.Write(ex.ToString(), "B_Menu_UpdateAllRights_error");
         return(Content("更新失败"));
     }
 }