Пример #1
0
        public IActionResult Get()
        {
            var pagination = Request.Headers["Pagination"];

            if (!string.IsNullOrEmpty(pagination))
            {
                string[] vals = pagination.ToString().Split(',');
                int.TryParse(vals[0], out page);
                int.TryParse(vals[1], out pageSize);
            }

            int currentPage     = page;
            int currentPageSize = pageSize;
            var totalCmsies     = _cmsRepository.Count();
            var totalPages      = (int)Math.Ceiling((double)totalCmsies / pageSize);

            IEnumerable <Cms> _cmss = _cmsRepository
                                      .AllIncluding(u => u.Fields, prop => prop.WorkItemType)
                                      .OrderBy(u => u.Id)
                                      .Skip((currentPage - 1) * currentPageSize)
                                      .Take(currentPageSize)
                                      .ToList();

            IEnumerable <CmsViewModel> _cmssVM = Mapper.Map <IEnumerable <Cms>, IEnumerable <CmsViewModel> >(_cmss);

            //TODO : Criar o View Model do CMS
            Response.AddPagination(page, pageSize, totalCmsies, totalPages);

            return(new OkObjectResult(_cmssVM));
        }