2026-08-17 21:06:40 +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;
|
2026-08-17 21:06:40 +07:00
|
|
|
|
2026-08-19 23:25:08 +07:00
|
|
|
namespace mws.backend.dotnet.application.Tasks;
|
2026-08-17 21:06:40 +07:00
|
|
|
|
2026-09-20 16:21:15 +07:00
|
|
|
public record DeleteTaskCommand(Guid UserId, Guid TaskId) : IRequest, IAuditableRequest
|
|
|
|
|
{
|
|
|
|
|
public string Action => "Task.Delete";
|
|
|
|
|
public string EntityType => "Task";
|
|
|
|
|
public Guid? EntityId => TaskId;
|
|
|
|
|
}
|
2026-08-17 21:06:40 +07:00
|
|
|
|
2026-09-20 16:21:15 +07:00
|
|
|
public class DeleteTaskHandler(IUnitOfWork uow, IAuditContext auditContext) : IRequestHandler<DeleteTaskCommand>
|
2026-08-17 21:06:40 +07:00
|
|
|
{
|
|
|
|
|
public async Task Handle(DeleteTaskCommand command, CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var task = await TaskAccess.GetTaskForUserAsync(uow, command.UserId, command.TaskId, ct);
|
|
|
|
|
uow.Tasks.Remove(task);
|
|
|
|
|
await uow.SaveChangesAsync(ct);
|
2026-09-20 16:21:15 +07:00
|
|
|
|
|
|
|
|
auditContext.EntityName = task.Title;
|
2026-08-17 21:06:40 +07:00
|
|
|
}
|
|
|
|
|
}
|