2026-08-19 23:25:08 +07:00
|
|
|
using MediatR;
|
2026-09-20 16:21:15 +07:00
|
|
|
using mws.backend.dotnet.application.Audit;
|
2026-08-19 23:25:08 +07:00
|
|
|
using mws.backend.dotnet.application.Common;
|
|
|
|
|
|
|
|
|
|
namespace mws.backend.dotnet.application.MasterData;
|
|
|
|
|
|
2026-09-20 16:21:15 +07:00
|
|
|
public record DeleteMasterDataCommand(Guid Id) : IRequest, IAuditableRequest
|
|
|
|
|
{
|
|
|
|
|
public string Action => "MasterData.Delete";
|
|
|
|
|
public string EntityType => "MasterData";
|
|
|
|
|
public Guid? EntityId => Id;
|
|
|
|
|
}
|
2026-08-19 23:25:08 +07:00
|
|
|
|
2026-09-20 16:21:15 +07:00
|
|
|
public class DeleteMasterDataHandler(IUnitOfWork uow, IAuditContext auditContext) : IRequestHandler<DeleteMasterDataCommand>
|
2026-08-19 23:25:08 +07:00
|
|
|
{
|
|
|
|
|
public async Task Handle(DeleteMasterDataCommand command, CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var entry = await uow.MasterData.GetByIdAsync(command.Id, ct)
|
|
|
|
|
?? throw new NotFoundException("Master data entry not found");
|
|
|
|
|
|
|
|
|
|
uow.MasterData.Remove(entry);
|
|
|
|
|
await uow.SaveChangesAsync(ct);
|
2026-09-20 16:21:15 +07:00
|
|
|
|
|
|
|
|
auditContext.EntityName = entry.Label;
|
2026-08-19 23:25:08 +07:00
|
|
|
}
|
|
|
|
|
}
|