示例#1
0
 public async Task <int> GetDataCount()
 {
     using (var sysUserRoleDao = new SysUserRoleDao())
     {
         return(await sysUserRoleDao.GetAllAsync().CountAsync());
     }
 }
示例#2
0
 /// <summary>
 /// 判断角色存在
 /// </summary>
 /// <param name="sysUserId">用户主键</param>
 /// <param name="sysRoleId">角色主键</param>
 /// <returns></returns>
 public async Task <bool> ExistsSysUserRole(Guid sysUserId, Guid sysRoleId)
 {
     using (IDAL.System.ISysUserRoleDao sysUserRoleDao = new SysUserRoleDao())
     {
         return(await sysUserRoleDao.GetAllAsync().AnyAsync(m => m.SysUserId == sysUserId && m.SysRoleId == sysRoleId));
     }
 }
示例#3
0
 /// <summary>
 /// 删除中间表信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public async Task RemoveSysUserRole(Guid id)
 {
     using (var sysUserRoleDao = new SysUserRoleDao())
     {
         await sysUserRoleDao.RemoveAsync(id);
     }
 }
示例#4
0
 /// <summary>
 /// 创建角色
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="roleId"></param>
 /// <returns></returns>
 public async Task CreateSysUserRole(Guid userId, Guid roleId)
 {
     using (var sysUserRoleDao = new SysUserRoleDao())
     {
         await sysUserRoleDao.CreateAsync(new SysUserRole()
         {
             SysUserId = userId,
             SysRoleId = roleId
         });
     }
 }
示例#5
0
 /// <summary>
 /// 查询所有中间表信息
 /// </summary>
 /// <param name="pageSize"></param>
 /// <param name="pageIndex"></param>
 /// <param name="asc"></param>
 /// <returns></returns>
 public async Task <List <DTO.System.SysUserRoleDto> > GetAllSysUserRole(int pageIndex = 1, int pageSize = 10, bool asc = true)
 {
     using (var sysUserRoleDao = new SysUserRoleDao())
     {
         return(await sysUserRoleDao.GetAllByPageOrderAsync(pageIndex - 1, pageSize, asc).Select(m => new DTO.System.SysUserRoleDto()
         {
             Id = m.Id,
             SysUserId = m.SysUserId,
             SysRoleId = m.SysRoleId,
             CreateTime = m.CreateTime
         }).ToListAsync());
     }
 }
示例#6
0
 /// <summary>
 /// 查询中间表信息
 /// </summary>
 /// <param name="sysUserRoleId"></param>
 /// <returns></returns>
 public async Task <DTO.System.SysUserRoleDto> GetOneSysUserRoleById(Guid sysUserRoleId)
 {
     using (IDAL.System.ISysUserRoleDao sysUserRoleDao = new SysUserRoleDao())
     {
         return(await sysUserRoleDao.GetAllAsync()
                .Where(m => m.Id == sysUserRoleId)
                .Select(m => new DTO.System.SysUserRoleDto()
         {
             Id = m.Id,
             SysUserId = m.SysUserId,
             SysRoleId = m.SysRoleId,
             CreateTime = m.CreateTime,
         }).FirstAsync());
     }
 }
示例#7
0
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="sysUserId"></param>
        /// <param name="sysRoleId"></param>
        /// <returns></returns>
        public async Task EditSysUserRole(Guid sysUserId, Guid[] sysRoleId)
        {
            using (var sysUserRoleDao = new SysUserRoleDao())
            {
                using (var sysUserDao = new SysUserDao())
                {
                    var user = await sysUserDao.GetOneByIdAsync(sysUserId);

                    foreach (var userRole in user.SysUserRoles)
                    {
                        if (sysRoleId.Contains(userRole.SysRoleId))
                        {
                            await sysUserRoleDao.EditAsync(userRole, false);
                        }
                    }
                    await sysUserRoleDao.Save();
                }
            }
        }
示例#8
0
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="sysUser"></param>
        /// <returns></returns>
        public async Task EditSysUser(SysUser sysUser, Guid[] sysRoleIds)
        {
            using (var sysUserDao = new SysUserDao())
            {
                var m = await sysUserDao.GetOneByIdAsync(sysUser.Id);

                m.UserName    = sysUser.UserName;
                m.RealName    = sysUser.RealName;
                m.SysDepartId = sysUser.SysDepartId;
                await sysUserDao.EditAsync(m);

                //中间表处理
                if (sysRoleIds != null)
                {
                    using (var sysUserRoleDao = new SysUserRoleDao())
                    {
                        var sysUserRoleList = sysUserRoleDao.GetAllAsync().Where(a => a.SysUserId == sysUser.Id);
                        //先清空
                        foreach (var item in sysUserRoleList)
                        {
                            await sysUserRoleDao.RemoveAsync(item, false);
                        }
                        await sysUserRoleDao.Save();

                        //添加
                        foreach (var roleId in sysRoleIds)
                        {
                            await sysUserRoleDao.CreateAsync(new SysUserRole()
                            {
                                SysUserId = sysUser.Id,
                                SysRoleId = roleId
                            }, false);
                        }
                        await sysUserRoleDao.Save();
                    }
                }
            }
        }
示例#9
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="sysUser"></param>
        /// <param name="sysRoleIds"></param>
        /// <returns></returns>
        public async Task Register(SysUser sysUser, Guid[] sysRoleIds)
        {
            using (var userDao = new SysUserDao())
            {
                await userDao.CreateAsync(sysUser);

                Guid userId = sysUser.Id;

                if (sysRoleIds != null)
                {
                    using (var sysUserRoleDao = new SysUserRoleDao())
                    {
                        foreach (var roleId in sysRoleIds)
                        {
                            await sysUserRoleDao.CreateAsync(new SysUserRole()
                            {
                                SysUserId = userId,
                                SysRoleId = roleId
                            });
                        }
                    }
                }
            }
        }