示例#1
0
        public List <FunctionModel> GetFunctionByUserIdAndMenuId(int userId, int menuId)
        {
            string cachekey = userId + "-" + menuId;

            var list = CacheManager.CreateCache().Get <List <FunctionModel> >(cachekey);

            if (list != null && list.Count > 0)
            {
                return(list);
            }

            list = new List <FunctionModel>(20);

            if (CommonAction.IsSysAdmin(userId))//如果是管理员 获取菜单所有的功能
            {
                var builtin = BuiltinRoles.All.Select(n => new FunctionModel {
                    FunctionKey = n, FunctionName = n
                });
                list.Add(new FunctionModel {
                    FunctionKey = "$ADMIN", FunctionName = "$ADMIN"
                });
                list.AddRange(builtin);
                list.AddRange(RoleNavigationFunctionDbAction.GetFunctionsByNavigationId(menuId));
            }
            else
            {
                var roles = UserRolesDbAction.GetUserRolses(userId);

                roles.ForEach(n =>
                {
                    if (BuiltinRoles.All.Contains(n.RoleName))
                    {
                        list.Add(new FunctionModel {
                            FunctionKey = n.RoleName, FunctionName = n.RoleName
                        });
                    }
                });

                //角色分配的功能
                var roleIds = roles.Select(p => p.RoleId).ToList();
                ICollection <FunctionModel> funcList     = RoleNavigationFunctionDbAction.GetFunctionsByRoleIdsAndNavigationId(roleIds, menuId);
                ICollection <FunctionModel> userFuncList = UserNavigationFunctionDbAction.GetFunctionsByUserIdsAndNavigationId(new List <int> {
                    userId
                }, menuId);

                list.AddRange(funcList);
                list.AddRange(userFuncList.Except(funcList).ToList());
            }

            CacheManager.CreateCache().Add(cachekey, list);

            return(list);
        }
示例#2
0
        public int UpdateUserRole(int userId, int creatId, List <int> listRole)
        {
            UserRolesDbAction.DeleteUserRoles(userId);

            var list = new List <Esmart_Sys_User_Roles>();

            if (listRole.Any())
            {
                list.AddRange(listRole.Select(lr => new Esmart_Sys_User_Roles()
                {
                    CreateId = creatId, CreateTime = DateTime.Now, RoleId = lr, UserId = userId
                }));
            }

            var result = UserRolesDbAction.AddList(list);

            CommonAction.ClearCache();
            return(result);
        }
示例#3
0
        /// <summary>
        /// 删除角色和角色对应的中间表数据
        /// Esmart_Sys_Roles
        /// Esmart_Sys_RolesInDeparent
        /// Esmart_Sys_Role_App
        /// Esmart_Sys_Role_Navigations
        /// Esmart_Sys_Role_Navigation_Function
        /// Esmart_Sys_User_Roles
        /// </summary>
        /// <param name="request">角色Id</param>
        /// <returns></returns>
        public bool Del(RoleModel request)
        {
            RoleDbAction.Delete(request.Id);
            RoleNavigationsDbAction.Del(request.Id);
            RoleNavigationFunctionDbAction.Del(request.Id);
            UserRolesDbAction.Delete(request.Id);
            DepartmentRolesDbAction.DeleteByRoleId(request.Id);
            if (LogHelper <RoleModel> .LogAction("Esmart.Permission.Application.Data.DepartmentRolesDbAction") != null)
            {
                LogHelper <RoleModel> .LogAction("Esmart.Permission.Application.Data.DepartmentRolesDbAction")(new UserLiteDto {
                    UserID = request.CreatorId == null?1:request.CreatorId.Value
                }, request);

                LogHelper <RoleModel> .RemoveAction("Esmart.Permission.Application.Data.DepartmentRolesDbAction");
            }
            var remark = string.Format("用户:{0} 删除角色:{1}", request.CreatorId ?? 0, request.Id);

            LogManagerDb.Log(request.CreatorId ?? 0, DateTime.Now, remark, "RoleManager.DelByDepartmentId");

            return(true);
        }
示例#4
0
        public SoaDataPageResponse <RoleModel> GetRoleList(SoaDataPage <RoleGridFilterViewModel> fiter)
        {
            SoaDataPageResponse <RoleModel> response = new SoaDataPageResponse <RoleModel>();

            List <Esmart_Sys_Roles> roles;

            if (CommonAction.IsSysAdmin(fiter.Where.LogInUserId))
            {
                roles = RoleDbAction.GetAllRols();

                response.Count = roles.Count;

                roles = roles.Skip((fiter.PageIndex - 1) * fiter.PageSize).Take(fiter.PageSize).ToList();
            }
            else
            {
                int count;
                roles          = UserRolesDbAction.GetRolesByUserId(fiter, out count);
                response.Count = count;
            }

            var body = roles.ConvertAll(a => new RoleModel()
            {
                CreateTime = a.CreateTime,
                CreatorId  = a.CreateId,
                EndDate    = a.EndTime,
                Id         = a.RoleId,
                Name       = a.RoleName,
                Remark     = a.Remark,
                StartDate  = a.StartTime,
                IsBuiltin  = a.IsBuiltin
            });

            response.Body = body;

            return(response);
        }
示例#5
0
 public int RemoveUserRole(int userId, int roleId)
 {
     return(UserRolesDbAction.RemoveUserRole(userId, roleId));
 }
示例#6
0
 public List <DepartmentUserResponse2> GetUsersOfRole(int roleId)
 {
     return(UserRolesDbAction.GetUsersWithRole(roleId));
 }
示例#7
0
        /// <summary>
        /// 获取用户或部门的可分配角色列表
        /// </summary>
        public List <RoleResponse> GetAssignRoles(int managerUserId, int deparentmentId, int targetUserId)
        {
            //-------------------------------------
            // 根据管理人获取可分配角色列表
            //-------------------------------------
            var assignableRoles = CommonAction.IsSysAdmin(managerUserId)
                ? RoleDbAction.GetAllRols()
                : UserRolesDbAction.GetUserRolses(managerUserId).Where(n => !BuiltinRoles.Admins.Contains(n.RoleName)).ToList();

            //-------------------------------------
            // 检索目标用户的已分配角色列表
            //-------------------------------------
            var assignedRoles = targetUserId > 0 ? UserRolesDbAction.GetUserRolses(targetUserId) : DepartmentRolesDbAction.GetAssignedRolesOfDepartment(deparentmentId);

            //-------------------------------------
            // 已分配角色列表和可分配角色列表交叉运算
            //-------------------------------------
            var response = assignableRoles.ConvertAll(a =>
            {
                var resp = new RoleResponse()
                {
                    RoleId   = a.RoleId,
                    RoleName = a.RoleName,
                    Remark   = a.Remark
                };

                if (a.StartTime != null)
                {
                    resp.StartTime = a.StartTime.Value.ToString("yyyy-MM-dd");
                }
                if (a.EndTime != null)
                {
                    resp.EndTime = a.EndTime.Value.ToString("yyyy-MM-dd");
                }

                var index = assignedRoles.FindIndex(n => n.RoleId == resp.RoleId);
                if (index >= 0)
                {
                    resp.IsChoice = true;
                    assignedRoles.RemoveAt(index);
                }
                return(resp);
            });

            if (assignedRoles.Count > 0)
            {
                response.InsertRange(0, assignedRoles.ConvertAll(a =>
                {
                    var resp = new RoleResponse()
                    {
                        RoleId   = a.RoleId,
                        RoleName = a.RoleName,
                        Remark   = a.Remark,
                        IsChoice = true
                    };

                    if (a.StartTime != null)
                    {
                        resp.StartTime = a.StartTime.Value.ToString("yyyy-MM-dd");
                    }
                    if (a.EndTime != null)
                    {
                        resp.EndTime = a.EndTime.Value.ToString("yyyy-MM-dd");
                    }
                    return(resp);
                }));
            }
            return(response.OrderBy(n => n.RoleName).ToList());
        }
示例#8
0
        public SoaDataPageResponse <UsersView> GetUsersByDepartList(SoaDataPage <UserSearchModel> filter)
        {
            SoaDataPageResponse <UsersView> response;

            if (filter.Where.DeapartmentId != 0)
            {
                response = DepartmentDbAction.GetUsersByDepartList(filter);
            }
            else
            {
                IQueryable <UsersView> query;

                if (CommonAction.IsSysAdmin(filter.Where.UserId))
                {
                    query = DepartmentUserDbAction.GetAllUsers(true).AsQueryable();
                }
                else
                {
                    var userList = new List <UsersView>(100);

                    var departments = DepartmentDbAction.GetDepartments(filter.Where.UserId);

                    foreach (var department in departments)
                    {
                        var users = DepartmentUserDbAction.GetUsersInDepartment(department.DeparentId, true);
                        userList.AddRange(users);
                    }

                    query = userList.AsQueryable();
                }

                if (!string.IsNullOrWhiteSpace(filter.Where.TrueName))
                {
                    query = query.Where(n => n.TrueName != null && n.TrueName.Contains(filter.Where.TrueName));
                }

                if (!string.IsNullOrWhiteSpace(filter.Where.Ename))
                {
                    query = query.Where(n => n.Ename != null && n.Ename.Contains(filter.Where.Ename));
                }

                if (!string.IsNullOrWhiteSpace(filter.Where.WorkNo))
                {
                    query = query.Where(n => n.WorkNo != null && n.WorkNo.Contains(filter.Where.WorkNo));
                }

                response = new SoaDataPageResponse <UsersView> {
                    Count = query.Count()
                };

                query = !string.IsNullOrWhiteSpace(filter.OrderBy) ? query.SortBy(filter.OrderBy + " " + filter.SortCol) : query.OrderByDescending(n => n.CreateTime);

                response.Body = query.Skip((filter.PageIndex - 1) * filter.PageSize).Take(filter.PageSize).ToList();
            }

            foreach (var user in response.Body)
            {
                user.RoleNames = string.Join(",", UserRolesDbAction.GetUserRoleNames(user.UserID));
            }

            return(response);
        }