23 lines
861 B
C#
23 lines
861 B
C#
using F9WebAiTest.Application.Common.Exceptions;
|
|
using F9WebAiTest.Domain.Interfaces.SYS.Departments;
|
|
using MediatR;
|
|
|
|
namespace F9WebAiTest.Application.CQRS.SYS.Departments.Commands;
|
|
|
|
/// <summary>命令定义</summary>
|
|
public record Department_DelCommand(long Id) : IRequest<bool>;
|
|
|
|
/// <summary>命令处理器</summary>
|
|
public class DelDepartmentCommandHandler(
|
|
IDepartmentWriteRepository departmentWriteRepository) : IRequestHandler<Department_DelCommand, bool>
|
|
{
|
|
public async Task<bool> Handle(Department_DelCommand command, CancellationToken cancellationToken)
|
|
{
|
|
if (command.Id <= 0) throw new F9OperationException("部门ID不能为空");
|
|
|
|
var result = await departmentWriteRepository.SoftDeleteAsync(command.Id);
|
|
if (result == false) throw new F9OperationException("部门", "删除");
|
|
return result;
|
|
}
|
|
}
|