예제 #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 totalAreas      = _areaRepository.Count();

            if (pageSize == 0)
            {
                pageSize        = totalAreas;
                currentPageSize = pageSize;
            }

            var totalPages = (int)Math.Ceiling((double)totalAreas / pageSize);

            IEnumerable <Area> _areas = _areaRepository
                                        .AllIncluding(a => a.Suggestions)
                                        .OrderBy(a => a.Id)
                                        .Skip((currentPage - 1) * currentPageSize)
                                        .Take(currentPageSize)
                                        .ToList();

            IEnumerable <AreaViewModel> _areasVM = Mapper.Map <IEnumerable <Area>, IEnumerable <AreaViewModel> >(_areas);

            Response.AddPagination(page, pageSize, totalAreas, totalPages);

            return(new OkObjectResult(_areasVM));
        }