public async Task <List <GetEmployeeDto> > Filter(FilterEmployeeDto filter) { var query = await _employeeRepository.Get(); if (filter.Id > 0) { query = query.Where(emp => emp.Id == filter.Id); } if (!filter.Name.IsEmpty()) { query = query.Where(emp => emp.Name.Like(filter.Name)); } if (!filter.Cpf.IsEmpty()) { query = query.Where(emp => emp.Cpf.Like(filter.Cpf.OnlyNumbers())); } if (!filter.Hiring.IsEmpty()) { query = query.Where(emp => emp.Hiring.HasValue && emp.Hiring.Value.Date == filter.Hiring.ToDate()); } if (!query.Any()) { return(null); } return(_mapper.Map <List <GetEmployeeDto> >(query.ToList())); }
public async Task <IActionResult> Get(FilterEmployeeDto filter) { var result = await _employeeService.Filter(filter); if (!_employeeService.Success()) { return(BadRequest(_employeeService.Errors)); } if (result.IsEmpty()) { return(NotFound()); } return(Ok(result)); }