public override Task <OperateDto> CreateOrEditOperate(OperateDto request, ServerCallContext context)
        {
            SysOperate data = null;

            if (request.Id == 0)
            {
                var entity = _operate.GetAll().OrderBy(item => item.Id).LastOrDefault();
                if (entity != null)
                {
                    request.Unique = entity.Unique + 1;
                }
                else
                {
                    request.Unique = 10001;
                }

                data = _operate.Insert(request.MapTo <SysOperate>());
            }
            else
            {
                data        = _operate.SingleOrDefault(item => item.Id == request.Id);
                data.Name   = request.Name;
                data.Remark = request.Remark;
                data        = _operate.Update(data);
            }

            return(Task.FromResult(data.MapTo <OperateDto>()));
        }
        public override Task <MenuDto> CreateOrEditMenu(CreateOrEditMenuRequest request, ServerCallContext context)
        {
            var menu = request.MapTo <SysMenu>();

            if (menu.Id > 0)
            {
                var oldMenu = _menu.SingleOrDefault(item => item.Id == menu.Id);
                oldMenu.Operates = menu.Operates;
                oldMenu.ParentId = menu.ParentId;
                oldMenu.Name     = menu.Name;
                oldMenu.Level    = menu.Level;
                oldMenu.Url      = menu.Url;
                oldMenu.Icon     = menu.Icon;
                menu             = _menu.Update(oldMenu);
            }
            else
            {
                var lastMenu = _menu.GetAll().OrderByDescending(item => item.Id).LastOrDefault();
                if (lastMenu != null && request.Id == 0)
                {
                    menu.Sort = lastMenu.AddOperateSort();
                }
                menu = _menu.Insert(menu);
            }

            return(Task.FromResult(menu.MapTo <MenuDto>()));
        }
Beispiel #3
0
        public override Task <TokenResponse> Token(TokenRequst request, ServerCallContext context)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "用户名不能为空"));
            }

            if (string.IsNullOrEmpty(request.Password))
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "密码不能为空"));
            }

            request.Password = request.Password.Get32MD5One();

            var sysUser =
                _sysUser.SingleOrDefault(item => item.UserName == request.Name && item.Password == request.Password);

            if (sysUser == null)
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "用户名密码错误"));
            }

            var appConfig = new Ketchup.Zero.Application.Config.AppConfig();

            return(Task.FromResult(new TokenResponse()
            {
                AccessToken = GenerateToken(appConfig),
                Expired = appConfig.Zero.AuthExpired,
                UserName = sysUser.UserName,
                RoleId = sysUser.RoleId,
                UserId = sysUser.Id
            }));
        }
Beispiel #4
0
        public override Task <TokenResponse> Login(TokenRequst request, ServerCallContext context)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "用户名不能为空"));
            }

            if (string.IsNullOrEmpty(request.Password))
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "密码不能为空"));
            }

            request.Password = request.Password.Get32MD5One();

            var sysUser =
                _sysUser.SingleOrDefault(item => item.UserName == request.Name && item.Password == request.Password);

            if (sysUser == null)
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "用户名密码错误"));
            }

            return(Task.FromResult(new TokenResponse()
            {
                UserName = sysUser.UserName,
                RoleId = sysUser.RoleId,
                UserId = sysUser.Id
            }));
        }
        public override Task <SysUserDto> CreateOrEditSysUser(SysUserDto request, ServerCallContext context)
        {
            if (request.Id == 1)
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "admin管理员不允许被修改"));
            }

            Domain.SysUser data = null;
            if (request.Id == 0)
            {
                request.Password = request.Password.Get32MD5One();
                data             = _sysUser.Insert(_mapper.Map <Domain.SysUser>(request));
            }
            else
            {
                data = _sysUser.SingleOrDefault(item => item.Id == request.Id);
                if (data == null)
                {
                    throw new RpcException(new Status(StatusCode.InvalidArgument, "系统用户不存在"));
                }

                data.RoleId   = request.RoleId;
                data.UserName = request.UserName;
                data          = _sysUser.Update(data);
            }

            return(Task.FromResult(_mapper.Map <SysUserDto>(data)));
        }
        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));
        }
Beispiel #7
0
        public override Task <RoleDto> CreateOrEditRole(RoleDto request, ServerCallContext context)
        {
            var role = request.MapTo <SysRole>();

            if (role.Id > 0)
            {
                var oldMenu = _role.SingleOrDefault(item => item.Id == role.Id);

                oldMenu.Name   = role.Name;
                oldMenu.Remark = role.Remark;
                role           = _role.Update(oldMenu);
            }
            else
            {
                role = _role.Insert(role);
            }

            return(Task.FromResult(role.MapTo <RoleDto>()));
        }
        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));
        }
Beispiel #9
0
        public override Task <SetRolePermissionResponse> SetRolePermission(SetRolepermissionRequest request,
                                                                           ServerCallContext context)
        {
            var result = new SetRolePermissionResponse {
                IsComplete = true
            };
            var datas = _roleMenu.GetAllList(item => item.RoleId == request.RoleId);

            if (datas.Count > 0)
            {
                _roleMenu.Delete(item => item.RoleId == request.RoleId);
            }

            if (request.MenuIds.Count == 0)
            {
                return(Task.FromResult(result));
            }

            var models = new List <RolePermissionDto>();
            var list   = new List <SysRoleMenu>();

            request.MenuIds.ToList().ForEach(item =>
            {
                var model        = new RolePermissionDto();
                var operateArray = item.Split('_');
                if (Convert.ToInt32(operateArray.LastOrDefault()) == 0)
                {
                    if (models.FirstOrDefault(m => m.MenuId == Convert.ToInt32(operateArray.FirstOrDefault())) != null)
                    {
                        return;
                    }
                    model.MenuId = Convert.ToInt32(operateArray.FirstOrDefault());
                    models.Add(model);
                }
                else
                {
                    var data = models.FirstOrDefault(m => m.MenuId == Convert.ToInt32(operateArray.FirstOrDefault()));
                    if (data == null)
                    {
                        model.MenuId = Convert.ToInt32(operateArray.FirstOrDefault());
                        model.Operates.Add(Convert.ToInt32(operateArray.LastOrDefault()));
                        models.Add(model);
                    }
                    else
                    {
                        data.Operates.Add(Convert.ToInt32(operateArray.LastOrDefault()));
                    }
                }
            });

            models.ForEach(rp =>
            {
                var menu = _menu.SingleOrDefault(item => item.Id == rp.MenuId);
                if (menu == null)
                {
                    return;
                }

                var roleMenu = new SysRoleMenu
                {
                    MenuId   = rp.MenuId,
                    RoleId   = request.RoleId,
                    Operates = JsonConvert.SerializeObject(menu.ParentId == 0
                        ? new List <int>()
                        : rp.Operates)
                };

                list.Add(roleMenu);
            });

            if (!_roleMenu.BatchInsert(list))
            {
                result.IsComplete = false;
            }

            return(Task.FromResult(result));
        }