Beispiel #1
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);
        }
Beispiel #2
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());
        }
Beispiel #3
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);
        }