Ejemplo n.º 1
0
        /// <summary>
        /// 根据菜单,获得当前菜单的所有功能权限
        /// </summary>
        /// <returns></returns>
        public Task <ApiResult <List <SysCodeDto> > > GetCodeByMenu(string role, string menu)
        {
            var res = new ApiResult <List <SysCodeDto> >()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                //获得角色权限Guid-List
                var menuModel = SysMenuDb.GetSingle(m => m.Guid == menu);
                //查询授权菜单里面的按钮功能
                var btnFunModel = SysPermissionsDb.GetSingle(m => m.RoleGuid == role && m.MenuGuid == menu && m.Types == 1);
                var codeList    = new List <SysCodeDto>();
                if (!string.IsNullOrEmpty(menuModel.BtnFunJson))
                {
                    var list = JsonConvert.DeserializeObject <List <string> >(menuModel.BtnFunJson);
                    codeList = SysCodeDb.GetList(m => list.Contains(m.Guid)).Select(m => new SysCodeDto()
                    {
                        guid     = m.Guid,
                        name     = m.Name,
                        codeType = m.CodeType,
                        status   = string.IsNullOrEmpty(btnFunModel.BtnFunJson)?false:btnFunModel.BtnFunJson.Contains(m.Guid)?true:false
                    }).ToList();
                }
                res.statusCode = (int)ApiEnum.Status;
                res.data       = codeList;
            }
            catch (Exception ex)
            {
                res.message = ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(Task.Run(() => res));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据菜单,获得当前菜单的所有功能权限
        /// </summary>
        /// <returns></returns>
        public ApiResult <List <SysCodeDto> > GetCodeByMenu(string role, string menu)
        {
            var res = new ApiResult <List <SysCodeDto> >()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                //获得角色权限Guid-List
                var menuModel = SysMenuDb.GetSingle(m => m.Guid == menu);
                if (menuModel == null)
                {
                    return(new ApiResult <List <SysCodeDto> >());
                }
                //查询授权菜单里面的按钮功能
                var btnFunModel = SysPermissionsDb.GetSingle(m => m.RoleGuid == role && m.MenuGuid == menu && m.Types == 1);
                if (btnFunModel == null)
                {
                    return(new ApiResult <List <SysCodeDto> >());
                }
                var list     = JsonConvert.DeserializeObject <List <string> >(menuModel.BtnFunJson);
                var codeList = Db.Queryable <SysCode>().Where(m => list.Contains(m.Guid)).Select(m => new SysCodeDto()
                {
                    guid     = m.Guid,
                    name     = m.Name,
                    codeType = m.CodeType,
                    status   = false
                }).ToList();

                if (btnFunModel != null && !string.IsNullOrEmpty(btnFunModel.BtnFunJson) && btnFunModel.BtnFunJson != "[]")
                {
                    foreach (var item in codeList)
                    {
                        if (btnFunModel.BtnFunJson.Contains(item.guid))
                        {
                            item.status = true;
                        }
                    }
                }

                res.statusCode = (int)ApiEnum.Status;
                res.data       = codeList;
            }
            catch (Exception ex)
            {
                res.message = ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(res);
        }
        /// <summary>
        /// 菜单授权-菜单功能
        /// role=角色
        /// funguid=按钮的编号
        /// status=取消还是授权
        /// </summary>
        /// <returns></returns>
        public Task <ApiResult <string> > RoleMenuToFunAsync(SysPermissionsParm parm)
        {
            var res = new ApiResult <string>()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                //根据角色和菜单查询内容
                var model = SysPermissionsDb.GetSingle(m => m.RoleGuid == parm.role &&
                                                       m.MenuGuid == parm.menu && m.Types == 1);
                if (model == null)
                {
                    res.message = "您还没有授权当前菜单功能模块";
                    return(Task.Run(() => res));
                }
                if (!string.IsNullOrEmpty(model.BtnFunJson))
                {
                    //判断授权还是取消
                    var list = JsonConvert.DeserializeObject <List <string> >(model.BtnFunJson);
                    if (parm.status == 0)
                    {
                        if (list.Contains(parm.btnfun))
                        {
                            list.Remove(parm.btnfun);
                        }
                    }
                    else
                    {
                        //授权
                        if (!list.Contains(parm.btnfun))
                        {
                            list.Add(parm.btnfun);
                        }
                    }
                    model.BtnFunJson = JsonConvert.SerializeObject(list);
                }
                else
                {
                    //肯定是增加
                    model.BtnFunJson = JsonConvert.SerializeObject(new List <string>()
                    {
                        parm.btnfun
                    });
                }
                Db.Updateable <SysPermissions>()
                .UpdateColumns(m => new SysPermissions()
                {
                    BtnFunJson = model.BtnFunJson
                })
                .Where(m => m.RoleGuid == parm.role &&
                       m.MenuGuid == parm.menu && m.Types == 1).ExecuteCommand();
                res.statusCode = (int)ApiEnum.Status;
            }
            catch (Exception ex)
            {
                res.message = ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(Task.Run(() => res));
        }