// GET: Servicos
        public async Task <IActionResult> Index(RequisicoesListViewModel model = null, int page = 1)
        {
            var total = await _context.Servico.CountAsync();

            if (page > (total / PageSize) + 1)
            {
                page = 1;
            }

            var servicos = await _context.Servico
                           .OrderBy(p => p.ServicoId)
                           .Skip((page - 1) * PageSize)
                           .Take(PageSize)
                           .ToListAsync();

            return(View(new ServicosListViewModel
            {
                Servicos = servicos,
                PagingInfo = new PaginationViewModel
                {
                    CurrentPage = page,
                    ItensPerPage = PageSize,
                    TotalItems = total
                }
            }));
        }
Esempio n. 2
0
        // GET: Requisicoes
        public async Task <IActionResult> Index(RequisicoesListViewModel model = null, int page = 1)
        {
            DateTime day = DateTime.MinValue;

            if (model != null && model.CurrentDay != DateTime.MinValue)
            {
                day = model.CurrentDay;
            }

            var databaseContext = _context.Requisicao.Include(r => r.Departamento)
                                  .Where(r => day == DateTime.MinValue || r.Detalhes.OrderBy(d => d.HoraDeInicio).FirstOrDefault().HoraDeInicio.Equals(day.Date));
            var total = await databaseContext.CountAsync();

            if (page > (total / PageSize) + 1)
            {
                page = 1;
            }

            var requisicoes = await databaseContext
                              .OrderByDescending(r => r.Dia)
                              .Skip((page - 1) * PageSize)
                              .Take(PageSize)
                              .ToListAsync();

            return(View(new RequisicoesListViewModel
            {
                Requisicoes = requisicoes,
                PagingInfo = new PaginationViewModel
                {
                    CurrentPage = page,
                    ItensPerPage = PageSize,
                    TotalItems = total
                },
                CurrentDay = day
            }));
        }