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));
        }
예제 #2
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);
        }
예제 #3
0
        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);
        }