first commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
|
||||
/// <summary>命令定义</summary>
|
||||
public record Role_UpdateCommand(long Id, string Name, string Code, int SortOrder, string Description) : IRequest<bool>;
|
||||
|
||||
/// <summary>命令处理器</summary>
|
||||
public class UpdateRoleCommandHandler(
|
||||
IRoleWriteRepository roleRepository) : IRequestHandler<Role_UpdateCommand, bool>
|
||||
{
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user