Esempio n. 1
0
        public async Task <IActionResult> GetEmployees(EmployeesResourceParameter employeesResourceParameter)
        {
            var result = await _personService.GetAllUsers(employeesResourceParameter);

            var previousPage = result.HasPrevious
                ? GetEmployeesUri(employeesResourceParameter, ResourceUriType.PreviousPage)
                : null;

            var nextPage = result.HasNext
                ? GetEmployeesUri(employeesResourceParameter, ResourceUriType.NextPage)
                : null;


            var metadata = new
            {
                totalCount   = result.TotalCount,
                pageSize     = result.PageSize,
                totalPages   = result.TotalPages,
                currentPage  = result.CurrentPage,
                nextPage     = nextPage,
                previousPage = previousPage,
                //   city = GetUserLocation()
            };

            Response.Headers.Add("Pagination", JsonConvert.SerializeObject(metadata));

            if (!result.Any())
            {
                return(NoContent());
            }

            return(Ok(result));
        }
Esempio n. 2
0
        private string GetEmployeesUri(EmployeesResourceParameter employeesResourceParameter,
                                       ResourceUriType type)
        {
            switch (type)
            {
            case ResourceUriType.PreviousPage:
                return(_uriHelper.Link("GetEmployees", new
                {
                    pageNumber = employeesResourceParameter.pageNumber - 1,
                    pageSize = employeesResourceParameter.PageSize
                }));

            case ResourceUriType.NextPage:
                return(_uriHelper.Link("GetEmployees", new
                {
                    pageNumber = employeesResourceParameter.pageNumber + 1,
                    pageSize = employeesResourceParameter.PageSize
                }));

            default:
                return(_uriHelper.Link("GetEmployees", new
                {
                    pageNumber = employeesResourceParameter.pageNumber,
                    pageSize = employeesResourceParameter.PageSize
                }));
            }
        }
Esempio n. 3
0
        public async Task <PagedList <ApplicationUserDto> > GetAllUsers(EmployeesResourceParameter employeesResourceParameter)
        {
            var result = await _personRepository.GetAllUsers(employeesResourceParameter);

            if (!result.Any())
            {
                return(null);
            }

            return(result);
        }
        public async Task <PagedList <ApplicationUserDto> > GetAllUsers(EmployeesResourceParameter employeesResourceParameter)
        {
            var result = DbSet.Include(x => x.Qualifications)
                         .SortOrder(employeesResourceParameter.SortingType)
                         .Include(x => x.UserRatings)
                         .Include(x => x.WorkPhotos)
                         .Include(x => x.Experiances);

            var pagedList = PagedList <ApplicationUser>
                            .Create(result, employeesResourceParameter.pageNumber, employeesResourceParameter.PageSize);

            var list = result.ToApplicationUserDtoList().ToList();

            return(new PagedList <ApplicationUserDto>(list, pagedList.Count,
                                                      employeesResourceParameter.pageNumber, employeesResourceParameter.PageSize));
        }