Ejemplo n.º 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 totalSchedules  = _fieldRepository.Count();
            var totalPages      = (int)Math.Ceiling((double)totalSchedules / pageSize);

            IEnumerable <Field> _fields = _fieldRepository
                                          .AllIncluding(s => s.Cms)
                                          .OrderBy(s => s.Id)
                                          .Skip((currentPage - 1) * currentPageSize)
                                          .Take(currentPageSize)
                                          .ToList();

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

            IEnumerable <FieldViewModel> _fieldsVM = Mapper.Map <IEnumerable <FieldViewModel> >(_fields);

            return(new OkObjectResult(_fieldsVM));
        }