public PagedList <Blacklist> GetBlacklists(BlacklistQueryFilter filters)
        {
            filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber;
            filters.PageSize   = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize;
            var blacklists = _unitOfWork.BlacklistRepository.GetAll();

            if (filters.filter != null)
            {
                blacklists = blacklists.Where(x => x.public_ip.ToLower().Contains(filters.filter.ToLower()));
            }
            if (filters.orderedBy != null && filters.orderedBy.Count() > 0)
            {
                foreach (var sortM in filters.orderedBy)
                {
                    blacklists = blacklists.OrderBy(sortM.PairAsSqlExpression);
                }
            }
            var pagedPosts = PagedList <Blacklist> .Create(blacklists, filters.PageNumber, filters.PageSize);

            return(pagedPosts);
        }
        public IActionResult GetBlacklists([FromBody] BlacklistQueryFilter filters)
        {
            var blacklists    = _blacklistService.GetBlacklists(filters);
            var blacklistsDto = _mapper.Map <IEnumerable <BlacklistDto> >(blacklists);
            var metadata      = new Metadata
            {
                TotalCount      = blacklists.TotalCount,
                PageSize        = blacklists.PageSize,
                CurrentPage     = blacklists.CurrentPage,
                TotalPages      = blacklists.TotalPages,
                HasNextPage     = blacklists.HasNextPage,
                HasPreviousPage = blacklists.HasPreviousPage,
                NextPageUrl     = _uriService.GetPostPaginationUri(filters, Url.RouteUrl(nameof(GetBlacklists))).ToString(),
                PreviousPageUrl = _uriService.GetPostPaginationUri(filters, Url.RouteUrl(nameof(GetBlacklists))).ToString()
            };
            var response = new ApiResponse <IEnumerable <BlacklistDto> >(blacklistsDto)
            {
                Meta = metadata
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));
            return(Ok(response));
        }
예제 #3
0
        public Uri GetPostPaginationUri(BlacklistQueryFilter filter, string actionUrl)
        {
            string baseUrl = $"{_baseUri}{actionUrl}";

            return(new Uri(baseUrl));
        }