Exemplo n.º 1
0
        /// <summary>
        /// 用户授权角色
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > ToRoleAsync(SysPermissions parm, bool status)
        {
            var res = new ApiResult <string>
            {
                statusCode = 200,
                data       = "1"
            };

            try
            {
                if (status)
                {
                    //授权
                    var dbres = SysPermissionsDb.Insert(new SysPermissions()
                    {
                        RoleGuid   = parm.RoleGuid,
                        AdminGuid  = parm.AdminGuid,
                        MenuGuid   = parm.MenuGuid,
                        BtnFunGuid = parm.BtnFunGuid,
                        Types      = parm.Types
                    });
                    if (!dbres)
                    {
                        res.statusCode = (int)ApiEnum.Error;
                        res.message    = "插入数据失败~";
                    }
                }
                else
                {
                    //取消授权
                    if (parm.Types == 2)
                    {
                        SysPermissionsDb.Delete(m => m.AdminGuid == parm.AdminGuid && m.RoleGuid == parm.RoleGuid && m.Types == 2);
                    }
                    if (parm.Types == 3)
                    {
                        //角色-菜单-按钮功能
                        SysPermissionsDb.Delete(m => m.BtnFunGuid == parm.BtnFunGuid && m.RoleGuid == parm.RoleGuid && m.MenuGuid == parm.MenuGuid && m.Types == 3);
                    }
                }
            }
            catch (Exception ex)
            {
                Db.Ado.CommitTran();
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public new async Task <ApiResult <string> > DeleteAsync(string parm)
        {
            var list = Utils.StrToListString(parm);
            var isok = SysAdminDb.Delete(m => list.Contains(m.Guid));

            //删除授权
            SysPermissionsDb.Delete(m => list.Contains(m.MenuGuid) && m.Types == 2);
            var res = new ApiResult <string>
            {
                statusCode = isok ? 200 : 500,
                data       = isok ? "1" : "0",
                message    = isok ? "删除成功~" : "删除失败~"
            };

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