Пример #1
0
        public JsonResult Authorize(string functionIds, int id)
        {
            var role = SysRole.SingleOrDefault(id);

            // 删除权限
            SysPower.Delete("where master_id in (@0) and master_type=@1", role.ID, MasterType.Role.ToString());

            // 角色授权
            if (string.IsNullOrEmpty(functionIds) == false)
            {
                var funcs = SysFunction.Fetch("where id in (@0)", functionIds.ToIntList());
                foreach (var func in funcs)
                {
                    SysPower power = new SysPower
                    {
                        FunctionID = func.ID,
                        MasterID   = role.ID,
                        MasterType = MasterType.Role.ToString()
                    };

                    power.Insert();
                }
            }

            // 刷新用户权限
            var users = SysUser.Fetch("where role_id=@0", role.ID);

            foreach (var user in users)
            {
                SysPower.Delete("where master_id in (@0) and master_type=@1", user.ID, MasterType.User.ToString());

                var powers = SysPower.Fetch("where master_id=@0 and master_type=@1", user.RoleID, MasterType.Role.ToString());

                foreach (var power in powers)
                {
                    try
                    {
                        SysPower newPower = new SysPower
                        {
                            FunctionID = power.FunctionID,
                            MasterID   = user.ID,
                            MasterType = MasterType.User.ToString()
                        };
                        newPower.Insert();
                    }
                    catch { }
                }
            }

            return(Json(ArtDialogResponseResult.SuccessResult));
        }
Пример #2
0
        private static void ResetUserPower(SysUser user)
        {
            // 重新赋权
            List <SysPower> powers = SysPower.Fetch("where master_id=@0 and master_type=@1", user.RoleID, MasterType.Role.ToString());

            foreach (var item in powers)
            {
                try
                {
                    SysPower power = new SysPower
                    {
                        FunctionID = item.FunctionID,
                        MasterID   = user.ID,
                        MasterType = MasterType.User.ToString()
                    };

                    power.Insert();
                }
                catch
                {
                }
            }
        }