Files
f9-web-ai-test/backend/F9WebAiTest.Application/CQRS/SYS/RBAC/Users/Commands/User_DelCommand.cs
T
2026-10-08 10:43:59 +08:00

23 lines
817 B
C#

using F9WebAiTest.Application.Common.Exceptions;
using F9WebAiTest.Domain.Interfaces.SYS.RBAC.Users;
using MediatR;
namespace F9WebAiTest.Application.CQRS.SYS.RBAC.Users.Commands;
/// <summary>命令定义</summary>
public record User_DelCommand(long Id) : IRequest<bool>;
/// <summary>命令处理器</summary>
public class DelUserCommandHandler(
IUserWriteRepository userWriteRepository) : IRequestHandler<User_DelCommand, bool>
{
public async Task<bool> Handle(User_DelCommand command, CancellationToken cancellationToken)
{
if (command.Id <= 0) throw new F9OperationException("用户ID不能为空");
var result = await userWriteRepository.SoftDeleteAsync(command.Id);
if (result == false) throw new F9OperationException("用户", "删除");
return result;
}
}