Exemple #1
0
        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="incrementRoleParam"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> AddRoleAsync(IncrementRoleParam incrementRoleParam, UserCacheBo currentUser)
        {
            var result = new ResponseModel <string>();
            var db     = SysRoleDao.CurrentDbContext;

            SysRoleDao.CloseTracking();
            if (await db.SysRoles.CountAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted) > 500)
            {
                return(result.Fail("一个租户下角色上限为500个"));
            }

            if (await db.SysRoles.AnyAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted && c.RoleName == incrementRoleParam.RoleName))
            {
                return(result.Fail("角色名已存在"));
            }

            var role = new SysRole()
            {
                TenantId    = currentUser.TenantId,
                CreatedBy   = currentUser.UserId,
                CreatedTime = DateTime.Now,
                Deleted     = false,
                RoleDesc    = incrementRoleParam.RoleDesc ?? "",
                RoleName    = incrementRoleParam.RoleName,
            };
            await db.SysRoles.AddAsync(role);

            var count = await db.SaveChangesAsync();

            return(count > 0 ? result.Succeed("添加成功") : result.Fail("添加失败"));
        }
Exemple #2
0
 /// <summary>
 /// 判断角色存在
 /// </summary>
 /// <param name="sysRoleId">用户角色主键</param>
 /// <returns></returns>
 public async Task <bool> ExistsSysRole(Guid sysRoleId)
 {
     using (IDAL.System.ISysRoleDao sysRoleDao = new SysRoleDao())
     {
         return(await sysRoleDao.GetAllAsync().AnyAsync(m => m.Id == sysRoleId));
     }
 }
Exemple #3
0
 public async Task <int> GetDataCount()
 {
     using (var sysRoleDao = new SysRoleDao())
     {
         return(await sysRoleDao.GetAllAsync().CountAsync());
     }
 }
Exemple #4
0
        //public async Task CreateSysRole(string roleName, int sortOrder)
        //{
        //    using (var sysRoleDao = new SysRoleDao())
        //    {
        //        await sysRoleDao.CreateAsync(new SysRole()
        //        {
        //            RoleName = roleName,
        //            SortOrder = sortOrder,

        //        });
        //    }
        //}


        public async Task RemoveSysRole(Guid id)
        {
            using (var sysRoleDao = new SysRoleDao())
            {
                await sysRoleDao.RemoveAsync(id);
            }
        }
Exemple #5
0
        //public async Task EditSysRole(Guid sysRoleId, string name)
        //{
        //    throw new NotImplementedException();
        //}

        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="sysRoleId"></param>
        /// <param name="roleName"></param>
        /// <param name="sortOrder"></param>
        /// <returns></returns>
        public async Task EditSysRole(Guid sysRoleId, string roleName, int sortOrder)
        {
            using (var sysRoleDao = new SysRoleDao())
            {
                var sysRole = await sysRoleDao.GetOneByIdAsync(sysRoleId);

                sysRole.RoleName  = roleName;
                sysRole.SortOrder = sortOrder;
                await sysRoleDao.EditAsync(sysRole);
            }
        }
Exemple #6
0
 /// <summary>
 /// 创建角色
 /// </summary>
 /// <param name="roleName"></param>
 /// <param name="sortOrder"></param>
 /// <returns></returns>
 public async Task CreateSysRole(string roleName, int sortOrder)
 {
     using (var sysRoleDao = new SysRoleDao())
     {
         await sysRoleDao.CreateAsync(new SysRole()
         {
             RoleName  = roleName,
             SortOrder = sortOrder
         });
     }
 }
Exemple #7
0
 /// <summary>
 /// 角色查询
 /// </summary>
 /// <param name="pageSize"></param>
 /// <param name="pageIndex"></param>
 /// <param name="asc"></param>
 /// <returns></returns>
 public async Task <List <DTO.System.SysRoleDto> > GetAllSysRole(int pageIndex = 1, int pageSize = 10, bool asc = true)
 {
     using (var sysRoleDao = new SysRoleDao())
     {
         return(await sysRoleDao.GetAllByPageOrderAsync(pageIndex - 1, pageSize, asc).Select(m => new DTO.System.SysRoleDto()
         {
             Id = m.Id,
             RoleName = m.RoleName,
             SortOrder = m.SortOrder,
             CreateTime = m.CreateTime
         }).OrderByDescending(m => m.SortOrder).ToListAsync());
     }
 }
Exemple #8
0
 public async Task <List <DTO.System.SysRoleDto> > GetAllSysRole()
 {
     using (var sysRoleDao = new SysRoleDao())
     {
         return(await sysRoleDao.GetAllAsync().Select(m => new DTO.System.SysRoleDto()
         {
             Id = m.Id,
             RoleName = m.RoleName,
             SortOrder = m.SortOrder,
             CreateTime = m.CreateTime
         }).OrderByDescending(m => m.SortOrder).ToListAsync());
     }
 }
Exemple #9
0
 /// <summary>
 /// 查询角色
 /// </summary>
 /// <param name="sysRoleId"></param>
 /// <returns></returns>
 public async Task <DTO.System.SysRoleDto> GetOneSysRoleById(Guid sysRoleId)
 {
     using (IDAL.System.ISysRoleDao sysRoleDao = new SysRoleDao())
     {
         return(await sysRoleDao.GetAllAsync()
                .Where(m => m.Id == sysRoleId)
                .Select(m => new DTO.System.SysRoleDto()
         {
             Id = m.Id,
             RoleName = m.RoleName,
             SortOrder = m.SortOrder,
             CreateTime = m.CreateTime,
         }).FirstAsync());
     }
 }
Exemple #10
0
        /// <summary>
        /// 获取角色信息列表 2014-09-11 14:58:50 By 唐有炜
        /// </summary>
        /// <param name="compNum">企业编号</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页的数目</param>
        /// <param name="rowCount">总数</param>
        /// <param name="orders">排序</param>
        /// <param name="predicate">条件</param>
        public IEnumerable <TSysRole> GetRoleLsit(string compNum, int pageIndex, int pageSize, out int rowCount,
                                                  IDictionary <string, teaCRM.Entity.teaCRMEnums.OrderEmum> orders,
                                                  Expression <Func <TSysRole, bool> > predicate)
        {
            IPagination <TSysRole> roles = null;

            try
            {
                roles = SysRoleDao.GetListByPage(pageIndex, pageSize, out rowCount, orders, predicate);
                LogHelper.Debug("获取角色列表成功。");
                return(roles);
            }
            catch (Exception ex)
            {
                rowCount = 0;
                LogHelper.Error("获取角色列表失败:", ex);
                return(null);
            }
        }
Exemple #11
0
        /// <summary>
        /// 校验当前角色是否能操作
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        private async Task <string> RoleIdCheckAsync(long roleId, UserCacheBo currentUser)
        {
            var role = await SysRoleDao.FirstAsync <SysRole>(c => c.RoleId == roleId && c.TenantId == currentUser.TenantId && !c.Deleted);

            if (currentUser.RoleIdList.Contains(roleId))
            {
                return("当前角色不可操作");
            }
            if (role == null)
            {
                return("角色不存在");
            }

            if (role.CreatedBy <= 0)
            {
                return("系统角色只读");
            }

            return("");
        }
Exemple #12
0
        /// <summary>
        /// 获取当前角色关联用户
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> GetRoleUserAsync(long roleId, UserCacheBo currentUser)
        {
            SysRoleDao.CloseTracking();
            var db = SysRoleDao.CurrentDbContext;
            var userRoleRelations = db.SysUserRoleRelations.Where(c => c.RoleId == roleId && !c.Deleted && c.TenantId == currentUser.TenantId);

            // 排除当前管理员 和 自己
            var users = db.SysUsers.Where(c => c.TenantId == currentUser.TenantId && c.CreatedBy > 0 && c.UserId != currentUser.UserId);

            var data = from user in users
                       join userRole in userRoleRelations on user.UserId equals userRole.UserId into ur1
                       from ur2 in ur1.DefaultIfEmpty()
                       select new
            {
                roleId   = ur2 == null ? -1 : ur2.RoleId,
                userId   = user.UserId,
                NickName = user.NickName
            };
            var result = await data.Distinct().ToListAsync();

            return(new ResponseModel().Succeed(result));
        }
Exemple #13
0
 /// <summary>
 /// 添加角色信息 2014-09-07 14:58:50 By 唐有炜
 /// </summary>
 /// <param name="sysRole"></param>
 /// <returns></returns>
 public bool AddRole(TSysRole sysRole)
 {
     return(SysRoleDao.InsertEntity(sysRole));
 }
Exemple #14
0
 /// <summary>
 /// 删除角色信息 2014-09-07 14:58:50 By 唐有炜
 /// </summary>
 /// <param name="id">角色</param>
 /// <returns></returns>
 public bool DeleteRole(int id)
 {
     return(SysRoleDao.DeleteEntity(d => d.Id == id));
 }
Exemple #15
0
        /// <summary>
        /// 用户管理界面获取可关联角色
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <PageResponse <RoleListDto> > GetCanRelationRoleList(UserCacheBo currentUser)
        {
            PageResponse <RoleListDto> roleList = await SysRoleDao.GetCanRelationRoleListAsync(currentUser);

            return(roleList);
        }
Exemple #16
0
        /// <summary>
        /// 获取角色及关联用户一览
        /// </summary>
        /// <param name="rolePageParam"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <PageResponse <RoleListDto> > RoleListAsync(RolePageParam rolePageParam, UserCacheBo currentUser)
        {
            PageResponse <RoleListDto> roleList = await SysRoleDao.RoleListAsync(rolePageParam, currentUser);

            return(roleList);
        }
Exemple #17
0
 /// <summary>
 /// 修改角色信息 2014-09-07 14:58:50 By 唐有炜
 /// </summary>
 /// <param name="sysRole"></param>
 /// <returns></returns>
 public bool UpdateRole(TSysRole sysRole)
 {
     return(SysRoleDao.UpadateEntity(sysRole));
 }
Exemple #18
0
 /// <summary>
 /// 获取单个角色信息 2014-09-07 14:58:50 By 唐有炜
 /// </summary>
 /// <param name="id">角色id</param>
 /// <returns></returns>
 public TSysRole GetRole(int id)
 {
     return(SysRoleDao.GetEntity(r => r.Id == id));
 }