-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEmployeeRepositoryAsync.cs
More file actions
42 lines (34 loc) · 1.58 KB
/
EmployeeRepositoryAsync.cs
File metadata and controls
42 lines (34 loc) · 1.58 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
37
38
39
40
41
namespace TalentManagementAPI.Infrastructure.Persistence.Repositories
{
public class EmployeeRepositoryAsync : GenericRepositoryAsync<Employee>, IEmployeeRepositoryAsync
{
private readonly DbSet<Employee> _repository;
private readonly IDataShapeHelper<Employee> _dataShaper;
public EmployeeRepositoryAsync(
ApplicationDbContext dbContext,
IDataShapeHelper<Employee> dataShaper) : base(dbContext)
{
_repository = dbContext.Set<Employee>();
_dataShaper = dataShaper;
}
public async Task<(IEnumerable<Entity> data, RecordsCount recordsCount)> GetEmployeeResponseAsync(GetEmployeesQuery requestParameters)
{
var recordsTotal = await _repository.CountAsync();
var filteredSpecification = new EmployeesByFiltersSpecification(requestParameters, applyPaging: false);
var pagedSpecification = new EmployeesByFiltersSpecification(requestParameters);
var recordsFiltered = await CountAsync(filteredSpecification);
var resultData = await ListAsync(pagedSpecification);
var shapedData = _dataShaper.ShapeData(resultData, requestParameters.Fields);
var recordsCount = BuildRecordsCount(recordsTotal, recordsFiltered);
return (shapedData, recordsCount);
}
private static RecordsCount BuildRecordsCount(int total, int filtered)
{
return new RecordsCount
{
RecordsFiltered = filtered,
RecordsTotal = total
};
}
}
}