Exemplo n.º 1
0
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > ModifyAsync(SysMenu parm, List <string> btnfun)
        {
            var res = new ApiResult <string>
            {
                statusCode = 200
            };
            //判断别名是否存在,要不一样的
            var isCodeExis = SysMenuDb.GetSingle(m => m.NameCode == parm.NameCode && m.Guid != parm.Guid);

            if (isCodeExis != null)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = "别名已存在~";
                return(await Task.Run(() => res));
            }
            parm.EditTime = DateTime.Now;
            if (!string.IsNullOrEmpty(parm.ParentGuid))
            {
                // 说明有父级  根据父级,查询对应的模型
                var model = SysMenuDb.GetById(parm.ParentGuid);
                parm.ParentGuidList = model.ParentGuidList + parm.Guid + ",";
                parm.Layer          = model.Layer + 1;
            }
            else
            {
                parm.ParentGuidList = "," + parm.Guid + ",";
            }
            parm.BtnFunJson = JsonConvert.SerializeObject(btnfun);
            await Db.Updateable(parm).ExecuteCommandAsync();

            return(res);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获得列表
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <Page <SysMenu> > > GetPagesAsync(PageParm parm)
        {
            var res = new ApiResult <Page <SysMenu> >();

            try
            {
                var query = await Db.Queryable <SysMenu>()
                            .WhereIF(!string.IsNullOrEmpty(parm.key), m => m.ParentGuidList.Contains(parm.key))
                            .OrderBy(m => m.Sort)
                            .Mapper((it, cache) =>
                {
                    var codeList = cache.Get(t =>
                    {
                        return(Db.Queryable <SysCode>().Where(m => m.ParentGuid == "a88fa4d3-3658-4449-8f4a-7f438964d716").ToList());
                    });
                    var list = new List <string>();
                    if (!string.IsNullOrEmpty(it.BtnFunJson))
                    {
                        list = JsonConvert.DeserializeObject <List <string> >(it.BtnFunJson);
                    }
                    if (list.Count > 0)
                    {
                        it.BtnFunJson = string.Join(',', codeList.Where(g => list.Contains(g.Guid)).Select(g => g.Name).ToList());
                    }
                })
                            .ToPageAsync(parm.page, parm.limit);

                res.success = true;
                res.message = "获取成功!";
                var result = new List <SysMenu>();
                if (!string.IsNullOrEmpty(parm.key))
                {
                    var menuModel = SysMenuDb.GetSingle(m => m.Guid == parm.key);
                    ChildModule(query.Items, result, menuModel.ParentGuid);
                }
                else
                {
                    ChildModule(query.Items, result, null);
                }

                query.Items = result;
                res.data    = query;
            }
            catch (Exception ex)
            {
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
                res.statusCode = (int)ApiEnum.Error;
            }
            return(res);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据唯一编号查询一条部门信息
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <SysMenu> > GetByGuidAsync(string parm)
        {
            var model = SysMenuDb.GetSingle(m => m.Guid == parm);
            var res   = new ApiResult <SysMenu>
            {
                statusCode = 200
            };
            var pmdel = Db.Queryable <SysMenu>().OrderBy(m => m.Sort, OrderByType.Desc).First();

            res.data = model ?? new SysMenu()
            {
                Sort = pmdel?.Sort + 1 ?? 1, Status = true
            };
            return(await Task.Run(() => res));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(SysMenu parm, List <string> btnfun)
        {
            var res = new ApiResult <string>
            {
                statusCode = 200,
                data       = "1"
            };
            //判断别名是否存在,要不一样的
            var isCodeExis = SysMenuDb.GetSingle(m => m.NameCode == parm.NameCode);

            if (isCodeExis != null)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = "别名已存在~";
                return(await Task.Run(() => res));
            }
            parm.Guid       = Guid.NewGuid().ToString();
            parm.EditTime   = DateTime.Now;
            parm.AddTIme    = DateTime.Now;
            parm.BtnFunJson = JsonConvert.SerializeObject(btnfun);
            SysMenuDb.Insert(parm);
            if (!string.IsNullOrEmpty(parm.ParentGuid))
            {
                // 说明有父级  根据父级,查询对应的模型
                var model = SysMenuDb.GetById(parm.ParentGuid);
                parm.ParentGuidList = model.ParentGuidList + parm.Guid + ",";
                parm.Layer          = model.Layer + 1;
            }
            else
            {
                parm.ParentGuidList = "," + parm.Guid + ",";
                parm.Layer          = 1;
            }

            //更新  新的对象
            SysMenuDb.Update(parm);

            return(await Task.Run(() => res));
        }