Ejemplo n.º 1
0
        public void LoadPermissions(Assembly assembly)
        {
            var permissions = assembly.GetTypes()
                              .SelectMany(x => x.GetMethods())
                              .Where(x => x.GetCustomAttributes <Preconditions.RequireCustomPermissionAttribute>().Count() > 0)
                              .Select(x => x.GetCustomAttribute <Preconditions.RequireCustomPermissionAttribute>().Permission);

            foreach (var p in permissions)
            {
                if (!AllPermissions.Contains(p))
                {
                    AllPermissions.Add(p);
                }
            }
        }
Ejemplo n.º 2
0
        //保存权限
        public JsonResult SaveRight(int permissionId, string rightName, string rightDesc, string controllerName, string actionName, string iconimg, int rightType, int parentRight, int showOrder = -1, string areaName = "")
        {
            try
            {
                SysPermission menu = AllPermissions.FirstOrDefault(p => p.PermissionId == permissionId);

                if (menu == null)
                {
                    //新增
                    menu = new SysPermission
                    {
                        PermissionName = rightName,
                        PermissionCode = rightDesc,
                        LinkUrl        = "",
                        Controller     = controllerName,
                        Action         = actionName,
                        ParentId       = parentRight,
                        Description    = rightDesc,
                        Sort           = showOrder,
                        Icon           = iconimg,
                        PermissionType = rightType,
                        AreaName       = areaName
                    };
                    _permissionManager.AddPermission(menu);
                    AllPermissions.Add(menu);
                }
                else
                {
                    menu.PermissionName = rightName;
                    menu.Description    = rightDesc;
                    menu.PermissionCode = rightDesc;
                    menu.LinkUrl        = "";
                    menu.Controller     = controllerName;
                    menu.Action         = actionName;
                    menu.Sort           = showOrder;
                    menu.Icon           = iconimg;
                    menu.PermissionType = rightType;
                    menu.AreaName       = areaName;
                    if (menu.Sort == int.MinValue)
                    {
                        menu.Sort = 0;
                    }
                    int newParentId = parentRight;
                    //修改前的判断
                    if (menu.PermissionId == newParentId)
                    {
                        return(Json(new
                        {
                            result = 0,
                            content = RetechWing.LanguageResources.Right.UpRightFails
                        }, JsonRequestBehavior.AllowGet));
                    }
                    var childs = new List <int>();

                    GetChildRights(menu.PermissionId, childs);

                    if (childs.IndexOf(newParentId) >= 0)
                    {
                        return(Json(new
                        {
                            result = 0,
                            content = RetechWing.LanguageResources.Right.UpRightFailsOne
                        }, JsonRequestBehavior.AllowGet));
                    }

                    menu.ParentId = newParentId;
                    _permissionManager.UpdatePermission(menu);
                }
                if (menu.PermissionId > 0)
                {
                    return(Json(new
                    {
                        result = 1,
                        content = RetechWing.LanguageResources.Common.SaveSuccess
                    }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new
                {
                    result = 0,
                    content = RetechWing.LanguageResources.Common.SaveFailed
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    result = 0,
                    content = RetechWing.LanguageResources.Common.SaveFailed + ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }