Last active
May 16, 2017 17:48
-
-
Save jfbueno/edcdb39e8b147bc28b946d9b898cf363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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