Exemplo n.º 1
0
        public Page <Employee> GetEmployeePage(Pageable pageable)
        {
            IList <Employee>       employees = GetAllEmployees();
            Page <Domain.Employee> page      = new Page <Domain.Employee>();
            int cix = employeeRepository.FindAll().Count;

            int pageSize   = pageable.getPageSize();
            int pageNumber = pageable.getPageNumber();

            page.setPageNumber(pageNumber);
            page.setPageSize(pageSize);

            var orderedEmployees = employees
                                   .OrderBy(employee => employee.Name);
            List <Domain.Employee> listed = orderedEmployees.ToList();

            int noOfElementsLeft  = listed.Count - (pageNumber - 1) * pageSize;
            int noOfelementsToPut = Constants.PAGE_SIZE;

            if (noOfElementsLeft < noOfelementsToPut)
            {
                noOfelementsToPut = noOfElementsLeft;
            }

            List <Domain.Employee> paged = listed.GetRange((pageNumber - 1) * pageSize, noOfelementsToPut);

            page.setNoOfElements(paged.Count);
            page.setItems(paged);
            return(page);
        }
Exemplo n.º 2
0
        public Page <Student> GetStudentPage(Pageable pageable)
        {
            IList <Student>       students = GetAllStudents();
            Page <Domain.Student> page     = new Page <Domain.Student>();

            int pageSize   = pageable.getPageSize();
            int pageNumber = pageable.getPageNumber();

            page.setPageNumber(pageNumber);
            page.setPageSize(pageSize);

            var orderedStudents = students
                                  .OrderBy(student => student.Name);
            List <Domain.Student> listed = orderedStudents.ToList();

            int noOfElementsLeft  = listed.Count - (pageNumber - 1) * pageSize;
            int noOfelementsToPut = Constants.PAGE_SIZE;

            if (noOfElementsLeft < noOfelementsToPut)
            {
                noOfelementsToPut = noOfElementsLeft;
            }

            List <Domain.Student> paged = listed.GetRange((pageNumber - 1) * pageSize, noOfelementsToPut);

            page.setNoOfElements(paged.Count);
            page.setItems(paged);
            return(page);
        }