예제 #1
0
        public override Task <RoleList> PageSerach(SearchRole request, ServerCallContext context)
        {
            var query = _role.GetAll().AsNoTracking();

            if (SearchFilter(request) != null)
            {
                query = query.Where(SearchFilter(request));
            }

            query = OrderFilter() != null
                 ? query.OrderByDescending(OrderFilter())
                 : query.OrderByDescending(item => item.Id);

            var total = query.Count();

            var result = query.Skip(request.PageMax * (request.PageIndex - 1))
                         .Take(request.PageMax)
                         .ToList();

            var date = new RoleList {
                Total = total
            };

            ConvertToEntities(result).ForEach(item =>
            {
                date.Datas.Add(item);
            });

            return(Task.FromResult(date));
        }
예제 #2
0
        public override Task <SearchSysUserResponse> PageSerachSysUser(SearchSysUser request, ServerCallContext context)
        {
            var query = _sysUser.GetAll().AsNoTracking();

            if (SearchFilter(request) != null)
            {
                query = query.Where(SearchFilter(request));
            }

            query = OrderFilter() != null
                ? query.OrderByDescending(OrderFilter())
                : query.OrderByDescending(item => item.Id);

            var total = query.Count();

            var result = query.Skip(request.PageMax * (request.PageIndex - 1))
                         .Take(request.PageMax)
                         .ToList();

            var date = new SearchSysUserResponse {
                Total = total
            };

            ConvertToEntities(result).ForEach(item =>
            {
                var role      = _role.SingleOrDefault(ro => ro.Id == item.RoleId);
                item.RoleName = role?.Name;
                date.Datas.Add(item);
            });

            return(Task.FromResult(date));
        }
예제 #3
0
        public override Task <MenutList> PageSerachMenu(SearchMenu request, ServerCallContext context)
        {
            var query = _menu.GetAll().AsNoTracking();

            if (SearchFilter(request) != null)
            {
                query = query.Where(SearchFilter(request));
            }

            query = OrderFilter() != null
                ? query.OrderByDescending(OrderFilter())
                : query.OrderByDescending(item => item.Id);

            var total = query.Count();

            var result = query.Skip(request.PageMax * (request.PageIndex - 1))
                         .Take(request.PageMax)
                         .ToList();

            var date = new MenutList {
                Total = total
            };

            ConvertToEntities(result).ForEach(item =>
            {
                JsonConvert.DeserializeObject <List <int> >(item.Operates).ForEach(operateId =>
                {
                    var operate = _operate.SingleOrDefault(ope => ope.Id == operateId);
                    if (operate == null)
                    {
                        return;
                    }
                    item.OperateModels.Add(new OperateModel()
                    {
                        Id = operateId, Name = operate.Name
                    });
                });

                date.Datas.Add(item);
            });

            return(Task.FromResult(date));
        }
예제 #4
0
        private List <SysMenu> GetRoleMenu(int roleId)
        {
            var menus           = new List <SysMenu>();
            var roleMenusByRole = _roleMenu.GetAll()
                                  .Where(item => item.RoleId == roleId)
                                  .OrderByDescending(item => item.MenuId)
                                  .ToList();

            if (roleMenusByRole.Count == 0)
            {
                return(menus);
            }
            roleMenusByRole.ForEach(rm =>
            {
                var menu = _menu.SingleOrDefault(item => item.Id == rm.MenuId);
                menus.Add(menu);
            });
            return(menus);
        }
예제 #5
0
        public override Task <RoleMenuReponse> GetMenusSetRole(MenusRoleRequest request, ServerCallContext context)
        {
            var result = new RoleMenuReponse();

            var datas     = _menu.GetAll().OrderBy(item => item.Id).AsNoTracking().ToList();
            var listMenus = new List <RoleMenuDto>();

            datas.ForEach(item =>
            {
                listMenus.Add(new RoleMenuDto
                {
                    ParentId = item.ParentId,
                    Id       = item.Id,
                    Title    = item.Name,
                    Icon     = item.Icon,
                    Path     = item.Url,
                    Operates = item.Operates,
                    Children = new List <RoleMenuDto>()
                });
            });

            var tree = listMenus.Where(item => item.ParentId == 99999).ToList();

            var operates = _operate
                           .GetAll()
                           .AsNoTracking()
                           .Select(item => new
            {
                item.Id,
                item.Name,
                item.Unique
            }).ToList();

            tree.ForEach(item => { BuildMeunsRecursiveTree(listMenus, item); });
            tree.ForEach(item =>
            {
                var model = new MenuModel {
                    Id = $"{item.Id}_0", Lable = item.Title
                };

                if (item.Children.Count > 0)
                {
                    item.Children.ForEach(child =>
                    {
                        var operateModel = new MenuModel {
                            Id = $"{child.Id}_0", Lable = child.Title
                        };
                        model.Children.Add(operateModel);
                        operates.ForEach(op =>
                        {
                            if (JsonConvert.DeserializeObject <List <int> >(child.Operates).Contains(op.Id))
                            {
                                operateModel.Children.Add(new MenuModel {
                                    Id = $"{child.Id}_{op.Id}", Lable = op.Name
                                });
                            }
                        });
                    });
                }
                result.List.Add(model);
            });
            var roleMenus = GetRoleOfMenus(request.RoleId);

            roleMenus.ForEach(item =>
            {
                if (item.Children.Count > 0)
                {
                    item.Children.ForEach(child =>
                    {
                        JsonConvert.DeserializeObject <List <int> >(child.Operates).ForEach(operateId =>
                        {
                            operates.ForEach(op =>
                            {
                                if (op.Id != operateId)
                                {
                                    return;
                                }
                                result.MenuIds.Add($"{child.Id}_{op.Id}");
                            });
                        });
                    });
                }
            });

            return(Task.FromResult(result));
        }