24 lines
943 B
C#
24 lines
943 B
C#
namespace Brizco.Repository.Handlers.Shift;
|
|
|
|
public class DeleteShiftCommandHandler : IRequestHandler<DeleteShiftCommand, bool>
|
|
{
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
|
|
public DeleteShiftCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
{
|
|
_repositoryWrapper = repositoryWrapper;
|
|
}
|
|
public async Task<bool> Handle(DeleteShiftCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>()
|
|
.TableNoTracking
|
|
.FirstOrDefaultAsync(s => s.Id == request.id, cancellationToken);
|
|
if (shift == null)
|
|
throw new AppException("Shift not found", ApiResultStatusCode.NotFound);
|
|
_repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>()
|
|
.Delete(shift);
|
|
|
|
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
return true;
|
|
}
|
|
} |