Beispiel #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 totalLeads      = _leadRepository.Count();
            var totalPages      = (int)Math.Ceiling((double)totalLeads / pageSize);


            IEnumerable <Lead> _leads = _leadRepository
                                        .GetAll()
                                        .OrderBy(u => u.Name)
                                        .Skip((currentPage - 1) * currentPageSize)
                                        .Take(currentPageSize)
                                        .ToList();

            IEnumerable <LeadViewModel> _leadsVM = Mapper.Map <IEnumerable <Lead>, IEnumerable <LeadViewModel> >(_leads);

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

            return(new OkObjectResult(_leadsVM));
        }