Example #1
0
        public HttpResponseMessage GetAll(HttpRequestMessage request, string keyword, int page, int pageSize = 20)
        {
            return(CreateHttpResponse(request, () =>
            {
                int totalRow = 0;
                var model = _postTagService.GetAll(keyword);

                totalRow = model.Count();
                var query = model.OrderByDescending(x => x.PostID).Skip(page * pageSize).Take(pageSize);

                var responseData = Mapper.Map <IEnumerable <PostTag>, IEnumerable <PostTagViewModel> >(query);

                var paginationSet = new PaginationSet <PostTagViewModel>()
                {
                    Items = responseData,
                    Page = page,
                    TotalCount = totalRow,
                    TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize)
                };
                var response = request.CreateResponse(HttpStatusCode.OK, paginationSet);
                return response;
            }));
        }