-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDeleteLeaveRequestCommandHandler.cs
More file actions
36 lines (31 loc) · 1.39 KB
/
Copy pathDeleteLeaveRequestCommandHandler.cs
File metadata and controls
36 lines (31 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using HR.LeaveManagement.Application.Exceptions;
using HR.LeaveManagement.Application.Features.LeaveRequests.Requests.Commands;
using HR.LeaveManagement.Application.Features.LeaveTypes.Requests.Commands;
using HR.LeaveManagement.Domain;
using RCommon.Mediator.Subscribers;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using RCommon.Persistence;
using RCommon.Persistence.Crud;
namespace HR.LeaveManagement.Application.Features.LeaveRequests.Handlers.Commands
{
public class DeleteLeaveRequestCommandHandler : IAppRequestHandler<DeleteLeaveRequestCommand>
{
private readonly IGraphRepository<LeaveRequest> _leaveRequestRepository;
public DeleteLeaveRequestCommandHandler(IGraphRepository<LeaveRequest> leaveRequestRepository)
{
this._leaveRequestRepository = leaveRequestRepository;
this._leaveRequestRepository.DataStoreName = DataStoreNamesConst.LeaveManagement;
}
public async Task HandleAsync(DeleteLeaveRequestCommand request, CancellationToken cancellationToken)
{
var leaveRequest = await _leaveRequestRepository.FindAsync(request.Id);
if (leaveRequest == null)
throw new NotFoundException(nameof(LeaveRequest), request.Id);
await _leaveRequestRepository.DeleteAsync(leaveRequest);
}
}
}