private void SearchForEmployee(int searchNumber) { var request = new GetEmployeeRequest(searchNumber); var response = this.employeeService.GetEmployee(request); if (response.Exception != null) { this.DisplayErrorMessage("Employee could not be found."); } else { this.CurrentEmployeeData = response.Employee; this.DisplayEmployeeData(response); } }
public GetEmployeeResponse GetEmployee(GetEmployeeRequest getEmployeeRequest) { GetEmployeeResponse response = new GetEmployeeResponse(); Employee employee; Employee manager; Department department; Salary salary; Title title; try { employee = this.employeeRepository.FindById(getEmployeeRequest.Id); if (employee != null) { var deptEmp = employee.Departments.OrderByDescending(d => d.FromDate).FirstOrDefault(); department = deptEmp != null ? deptEmp.Department : null; salary = employee.Salaries.OrderByDescending(d => d.FromDate).FirstOrDefault(); title = employee.Titles.OrderByDescending(d => d.FromDate).FirstOrDefault(); manager = employee.Managers.OrderByDescending(d => d.FromDate).Select(m => m.Employee).FirstOrDefault(); response.Employee = employee.ConvertToViewModel(department, manager, salary, title); } else { response.Exception = this.GetStandardEmployeeNotFoundException(getEmployeeRequest.Id); } } catch (Exception ex) { response.Exception = ex; } return response; }