public async Task <PagedResultDto <EmployeeDto> > GetAll(GetEmployeeInputDto input) { var query = _repository.WhereIf(!string.IsNullOrWhiteSpace(input.Filter), _ => _.Name.Contains(input.Filter)); if (input.OrgId.HasValue) { var org = await _orgRepository.GetAsync(input.OrgId.Value); var orgIds = await _orgRepository.Where(_ => _.CascadeId.Contains(org.CascadeId)).Select(_ => _.Id).ToListAsync(); query = query.Where(_ => orgIds.Contains(_.OrgId)); } var totalCount = await query.CountAsync(); var items = await query.OrderBy(input.Sorting ?? "Name") .ToListAsync(); var orgs = await _orgRepository.Where(_ => items.Select(i => i.OrgId).Contains(_.Id)).ToListAsync(); var dots = ObjectMapper.Map <List <Employee>, List <EmployeeDto> >(items); foreach (var dto in dots) { dto.OrgIdToName = orgs.FirstOrDefault(_ => _.Id == dto.OrgId)?.Name; } return(new PagedResultDto <EmployeeDto>(totalCount, dots)); }
public async Task <PagedResultDto <EmployeeDto> > GetAll(GetEmployeeInputDto input) { var query = _repository.WhereIf(!string.IsNullOrWhiteSpace(input.Filter), _ => _.Name.Contains(input.Filter)); var totalCount = await query.CountAsync(); var items = await query.OrderBy(input.Sorting ?? "Name") .ToListAsync(); var dots = ObjectMapper.Map <List <Employee>, List <EmployeeDto> >(items); return(new PagedResultDto <EmployeeDto>(totalCount, dots)); }
public Task <PagedResultDto <EmployeeDto> > GetAll(GetEmployeeInputDto input) { return(_employeeAppService.GetAll(input)); }