Exemple #1
0
        public void ClearRoleUserCache(long roleId)
        {
            //user2role 找到userid
            var userIdLst = User2RoleRepository
                            .QueryEnable()
                            .Where(m => m.RoleId == roleId)
                            .Select(m => m.UserId)
                            .ToList();

            //user2apart  role2apart 找到userid
            var user2ApartQuery = User2ApartRepository
                                  .QueryEnable();
            var role2ApartQuery = Role2ApartRepository
                                  .QueryEnable()
                                  .Where(m => m.RoleId == roleId);
            var apart2UserIdList = user2ApartQuery
                                   .Join(role2ApartQuery,
                                         u2a => u2a.ApartmentId,
                                         r2a => r2a.ApartmentId,
                                         (u2a, r2a) => u2a.UserId);

            //合集
            userIdLst.AddRange(apart2UserIdList);

            //剔除重复
            userIdLst = userIdLst.Distinct().ToList();

            //清除缓存
            foreach (var userId in userIdLst)
            {
                Cache.Remove(Users.GIdPrefix + userId);
            }
        }
Exemple #2
0
        public List <long> GetRoleIdList(long userId)
        {
            if (userId == 0)
            {
                return(new List <long>());
            }
            //用户x角色
            var user2RoleIdList = User2RoleRepository
                                  .QueryEnable()
                                  .Where(m => m.UserId == userId)
                                  .Select(m => m.RoleId)
                                  .ToList();

            //用户x部门x角色
            var user2ApartQuery = User2ApartRepository
                                  .QueryEnable()
                                  .Where(m => m.UserId == userId);
            var role2ApartQuery = Role2ApartRepository
                                  .QueryEnable();
            var apart2RoleIdList = user2ApartQuery
                                   .Join(role2ApartQuery,
                                         u2a => u2a.ApartmentId,
                                         r2a => r2a.ApartmentId,
                                         (u2a, r2a) => r2a.RoleId);

            //RoleIdList
            user2RoleIdList.AddRange(apart2RoleIdList);
            var roleIdList = user2RoleIdList
                             .Distinct()
                             .ToList();

            return(roleIdList);
        }
        public async Task <ActionResult> SetRole(long userId, string roleIds)
        {
            var result = new JsonModel();
            await User2RoleRepository.SaveListAsync(userId, roleIds);

            result.message = "保存成功!";
            return(Json(result));
        }
Exemple #4
0
        public ActionResult SetRole(SetRoleModel model)
        {
            var result = new JsonModel();

            User2RoleRepository.SaveList(model.UserIds, model.RoleIds);
            result.msg  = "保存成功!";
            result.code = JsonModelCode.Succ;
            return(Json(result));
        }
        public async Task <ActionResult> SetRole(long userId)
        {
            var model = new SetRoleModel()
            {
                UserId             = userId,
                SelectedRoleIdList = await User2RoleRepository.GetRoleIdListAsync(userId),
                UserRoleList       = await UserRoleRepository.GetListAsync()
            };

            return(PartialView(model));
        }
Exemple #6
0
        public Task <List <Users> > GetUserListByRoleIds(string roleIds)
        {
            if (string.IsNullOrEmpty(roleIds))
            {
                return(Task.FromResult <List <Users> >(null));
            }
            var roleIdArray = StringUtility.ConvertToBigIntArray(roleIds, ',');

            var userIdList = User2RoleRepository
                             .AdminQueryEnable()
                             .Where(m => roleIdArray.Contains(m.RoleId))
                             .Select(m => m.UserId)
                             .Distinct();
            var userList = UserRepository
                           .AdminQueryEnable()
                           .Where(m => userIdList.Contains(m.Id))
                           .ToListAsync();

            return(userList);
        }
        public void ClearRoleUserCache(long roleId)
        {
            //user2role 找到userid
            var lstUserId = User2RoleRepository.GetLstUserId(roleId);

            //user2apart  role2apart 找到userid
            var lstApartId     = Role2ApartRepository.GetLstApartId(roleId);
            var lstApartUserId = User2ApartRepository.GetLstUserId(lstApartId);

            //合集
            lstUserId.Concat(lstApartUserId);

            //剔除重复
            lstUserId = lstUserId.Distinct().ToList();

            //清除缓存
            foreach (var userId in lstUserId)
            {
                Cache.Remove(Users.GIdPrefix + userId);
            }
        }
        public List <long> GetRoleIdList(long userId)
        {
            if (userId == 0)
            {
                return(new List <long>());
            }
            //用户x角色
            var lstU2RRoleId = User2RoleRepository.GetLstRoleId(userId);

            //用户x部门x角色
            var lstApartId   = User2ApartRepository.GetLstApartId(userId);
            var lstR2ARoleId = Role2ApartRepository.GetLstRoleId(lstApartId);

            //RoleIdList
            lstU2RRoleId.Concat(lstR2ARoleId);
            var roleIdList = lstU2RRoleId
                             .Distinct()
                             .ToList();

            return(roleIdList);
        }