public async Task <IActionResult> Index(string sortOrder, string currentFilter, string searchString, int?pageNumber) { ViewBag.Title = "Situação Base"; ViewData["CurrentSort"] = sortOrder; ViewData["SituacaoBaseSortParm"] = String.IsNullOrEmpty(sortOrder) ? "situacao_base" : ""; ViewData["DescSituacaoBaseSortParm"] = sortOrder == "Situacao" ? "situacaobase_desc" : "Situacao"; if (searchString != null) { pageNumber = 1; } else { searchString = currentFilter; } ViewData["CurrentFilter"] = searchString; var sitbase = await _situacaobaseRepo.GetAsync(); if (!String.IsNullOrEmpty(searchString)) { sitbase = sitbase.Where(s => s.Situacao.ToUpper().Contains(searchString.ToUpper()) || s.Descricao.ToUpper().Contains(searchString.ToUpper())); } switch (sortOrder) { case "situacao_base": sitbase = sitbase.OrderByDescending(s => s.Situacao); break; case "Situacao": sitbase = sitbase.OrderBy(s => s.Descricao); break; case "situacaobase_desc": sitbase = sitbase.OrderByDescending(s => s.Descricao); break; default: sitbase = sitbase.OrderBy(s => s.Descricao); break; } int pageSize = 20; // Número de registros por Página return(View(PaginatedList <SituacaoBase> .Create(sitbase.AsQueryable(), pageNumber ?? 1, pageSize))); }
private async Task getSituacaoBaseSelect() { var situacao = await _situacaobaseRepo.GetAsync(); ViewBag.SituacaoDaBase = situacao.Select(c => new SelectListItem { Value = c.Situacao, Text = c.Descricao }); }