/// <summary> /// Requests a list of employees that fit the filter criteria /// </summary> /// <param name="filterInfo"></param> /// <returns></returns> public async Task <List <EmployeeDto> > FilterEmployees(EmployeeFilterInfo filterInfo) { _loggingService.LogDebug(new { action = nameof(FilterEmployees), filterInfo = filterInfo.ToString() }); return(await _apiService.PostAsync <EmployeeFilterInfo, List <EmployeeDto> >("Employee/FilterEmployees", filterInfo)); }
/// <summary> /// returns the filtered employees depending onthe filterinfo /// </summary> /// <param name="filterInfo"></param> /// <returns></returns> public async Task <AlpApiResponse <List <EmployeeDto> > > FilterEmployees(EmployeeFilterInfo filterInfo) { var response = new AlpApiResponse <List <EmployeeDto> >(); try { _logger.LogDebug(new { action = nameof(FilterEmployees), info = filterInfo?.ToString() }.ToString()); var nameIsNull = string.IsNullOrEmpty(filterInfo.Name); var employees = await _context.Employee.AsNoTracking() .Include(employee => employee.Department) .Include(employee => employee.Section) .Where(employee => (nameIsNull || employee.EmployeeName.Contains(filterInfo.Name)) && (!filterInfo.DepartmentId.HasValue || employee.DepartmentId == filterInfo.DepartmentId) && (!filterInfo.SectionId.HasValue || employee.SectionId == filterInfo.SectionId)) .ToListAsync(); response.Value = employees.Select(employee => employee.EntityToDto()).ToList(); foreach (var dto in response.Value) { dto.HasAccess = await _context.Account.AsNoTracking().AnyAsync(acc => acc.EmployeeId == dto.Id); } } catch (Exception e) { _logger.LogError(new { exception = e, message = e.Message, innerException = e, innerExceptionMessage = e.InnerException?.Message }.ToString()); response.Message = e.Message; response.Success = false; } return(response); }