using F9WebAiTest.Application.Common.Exceptions; using F9WebAiTest.Domain.Entities.SYS.RBAC; using F9WebAiTest.Domain.Interfaces.SYS.RBAC.Roles; using MediatR; namespace F9WebAiTest.Application.CQRS.SYS.RBAC.Roles.Commands; /// 命令定义 public record Role_UpdateCommand(long Id, string Name, string Code, int SortOrder, string Description) : IRequest; /// 命令处理器 public class UpdateRoleCommandHandler( IRoleWriteRepository roleRepository) : IRequestHandler { public async Task Handle(Role_UpdateCommand command, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(command.Name)) throw new F9OperationException("角色名称不能为空"); if (string.IsNullOrWhiteSpace(command.Code)) throw new F9OperationException("角色编码不能为空"); var newEntity = new Role(command.Id, command.Name, command.Code, command.SortOrder, command.Description); var result = await roleRepository.UpdateAsync(newEntity); if (result == false) throw new F9OperationException("角色", "修改"); return result; } }