public EntityPage <EmployeeDto> Handle(GetPagedEmployees request) { var employees = employeeRepository.PagedList(request.PageNumber, request.PageSize); if (employees != null) { var employeePage = employees.Select(x => employeeDtoBuilder.Build(x)); var pageCount = employees.PageCount; var entityPage = new EntityPage <EmployeeDto>(employeePage, request.PageNumber, pageCount); return(entityPage); } return(new EntityPage <EmployeeDto>(new List <EmployeeDto>(), request.PageNumber, 0)); }
public EmployeeDto Handle(AddEmployee request) { var employee = employeeFactory.Create( request.AddEmployeeForm.FirstName, request.AddEmployeeForm.LastName, request.AddEmployeeForm.MiddleName, request.AddEmployeeForm.Phone, request.AddEmployeeForm.CompanyId); employeeRepository.Add(employee); employeeRepository.SaveChanges(); var employeeDto = employeeDtoBuilder.Build(employee); return(employeeDto); }
public EmployeeDto Handle(EditEmployee request) { var employee = employeeRepository.Find(request.Id); if (employee == null) { throw new NotFoundException(); } employee.FirstName = request.EditEmployeeForm.FirstName; employee.LastName = request.EditEmployeeForm.LastName; employee.MiddleName = request.EditEmployeeForm.MiddleName; employee.Phone = request.EditEmployeeForm.Phone; employee.CompanyId = request.EditEmployeeForm.CompanyId; employeeRepository.Update(employee); employeeRepository.SaveChanges(); var employeeDto = employeeDtoBuilder.Build(employee); return(employeeDto); }