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>())); }
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 <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 <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>())); }