Skip to content

Instantly share code, notes, and snippets.

@jfbueno
Last active May 16, 2017 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfbueno/edcdb39e8b147bc28b946d9b898cf363 to your computer and use it in GitHub Desktop.
Save jfbueno/edcdb39e8b147bc28b946d9b898cf363 to your computer and use it in GitHub Desktop.
public async Task<ActionResult> Index(int? pagina, TituloViewModel viewModel)
{
var paginaNaoNula = pagina ?? 1;
Guid usuarioId = Guid.Parse(User.Identity.GetUserId());
var clientes = await db.Clientes.Where(c => c.UsuarioId == usuarioId).Include(cliente => cliente.Usuario).AsQueryable();
if (!string.IsNullOrEmpty(viewModel.NomeCompleto))
clientes = clientes.Where(p => p.Nome.Contains(viewModel.NomeCompleto));
if (viewModel.DataCadastro != null)
clientes = cliente.Where(p => p.DataCadastro <= viewModel.DataCadastro);
if (viewModel.DataVencimento != null)
clientes = clientes.Where(p => p.Titulo.DataExpiracao.Date <= viewModel.DataVencimento);
var lista = await clientes.ToListAsync();
var listaTitulos = new List<TituloViewModel>();
listaTitulos.AddRange(lista.Select(item => new TituloViewModel
{
NomeCompleto = $"{item.Nome} {item.Sobrenome}",
DataCadastro = item.Titulo.DataCadastro,
DataVencimento = item.Titulo.DataExpiracao
}));
var retorno = await listaTitulos.OrderBy(l => l.NomeCompleto).ToPagedListAsync(paginaNaoNula, 15);
return View(retorno);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment