public ActionResult <IEnumerable <EmployeeDTO> > GetEmployees([FromQuery] EmployeeResourceParameter employeeResourceParameter) { //throw new Exception("Test"); var employeesFromRepo = _employeeRepository.GetEmployees(employeeResourceParameter); return(Ok(_mapper.Map <IEnumerable <EmployeeDTO> >(employeesFromRepo))); }
public IEnumerable <Entities.Employee> GetEmployees(EmployeeResourceParameter employeeResourceParameter) { if (employeeResourceParameter == null) { throw new ArgumentNullException(nameof(employeeResourceParameter)); } if (string.IsNullOrWhiteSpace(employeeResourceParameter.DepartmentName) && string.IsNullOrWhiteSpace(employeeResourceParameter.SearchQuery)) { return(GetEmployees()); } var collection = _context.Employees as IQueryable <Entities.Employee>; var employeesWithDepartmentName = new List <Entities.Employee>(); foreach (var employee in collection) { employeesWithDepartmentName.Add(new Entities.Employee { Id = employee.Id, FirstName = employee.FirstName, LastName = employee.LastName, DateOfBirth = employee.DateOfBirth, DepartmentId = employee.DepartmentId, Department = _context.Departments.FirstOrDefault(u => u.Id == employee.DepartmentId) }); } if (!string.IsNullOrWhiteSpace(employeeResourceParameter.DepartmentName)) { var departmentName = employeeResourceParameter.DepartmentName.Trim(); employeesWithDepartmentName = employeesWithDepartmentName.Where(a => a.Department.DepartmentName == departmentName).ToList(); } if (!string.IsNullOrWhiteSpace(employeeResourceParameter.SearchQuery)) { var searchQuery = employeeResourceParameter.SearchQuery.Trim(); employeesWithDepartmentName = employeesWithDepartmentName.Where(a => a.FirstName.Contains(searchQuery) || a.LastName.Contains(searchQuery)).ToList(); } return(employeesWithDepartmentName); }
private IEnumerable <LinkDto> CreateLinksForEmployees(EmployeeResourceParameter employeeResourceParameters, bool hasNext, bool hasPrevious) { var links = new List <LinkDto>(); //self links.Add(new LinkDto(ResourceUriGenerator.CreateAuthorResourceUri(employeeResourceParameters, ResourceUriType.Current, Url), "AllEmployee", "GET")); if (hasNext) { links.Add(new LinkDto(ResourceUriGenerator.CreateAuthorResourceUri(employeeResourceParameters, ResourceUriType.NextPage, Url), "nextPage", "GET")); } if (hasNext) { links.Add(new LinkDto(ResourceUriGenerator.CreateAuthorResourceUri(employeeResourceParameters, ResourceUriType.PreviousPage, Url), "previousPage", "GET")); } return(links); }
public static string CreateAuthorResourceUri(EmployeeResourceParameter authorResourceParameters, ResourceUriType type, IUrlHelper Url) { switch (type) { case ResourceUriType.PreviousPage: return(Url.Link("GetAuthors", new { fields = authorResourceParameters.Fields, orderBy = authorResourceParameters.OrderBy, PageNumber = authorResourceParameters.PageNumber - 1, pageSize = authorResourceParameters.PageSize, searchQuery = authorResourceParameters.SearchQuery })); case ResourceUriType.NextPage: return(Url.Link("GetAuthors", new { fields = authorResourceParameters.Fields, orderBy = authorResourceParameters.OrderBy, PageNumber = authorResourceParameters.PageNumber + 1, pageSize = authorResourceParameters.PageSize, searchQuery = authorResourceParameters.SearchQuery })); case ResourceUriType.Current: default: return(Url.Link("GetAuthors", new { fields = authorResourceParameters.Fields, orderBy = authorResourceParameters.OrderBy, PageNumber = authorResourceParameters.PageNumber, pageSize = authorResourceParameters.PageSize, searchQuery = authorResourceParameters.SearchQuery })); } }