Created
November 9, 2009 21:07
-
-
Save jfromaniello/230278 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq.Expressions; | |
using System.Windows.Input; | |
using Mantenimiento.Domain.Model.InterfacesBase; | |
using uNhAddIns.Entities; | |
namespace Mantenimiento.ViewModels.BaseClasses | |
{ | |
public abstract class ViewModelPaginado<T> : ViewModelBase where T : Entity | |
{ | |
private readonly IModeloListar<T> _modelo; | |
private ICollection<T> _lista; | |
private int _totalPaginas; | |
private int _paginaActual; | |
protected ViewModelPaginado(IModeloListar<T> modelo) | |
{ | |
_modelo = modelo; | |
TotalPaginas = modelo.ObtenerUltimaPagina(Constantes.TAMANIO_PAGINA, a => true); | |
PaginaActual = 0; | |
Lista = modelo.ObtenerPagina(Constantes.TAMANIO_PAGINA, 0, a => true, CrearOrden()); | |
} | |
public ICollection<T> Lista | |
{ | |
get { return _lista; } | |
private set | |
{ | |
_lista = value; | |
OnPropertyChanged("Lista"); | |
} | |
} | |
public int PaginaActual | |
{ | |
get { return _paginaActual; } | |
private set | |
{ | |
_paginaActual = value; | |
OnPropertyChanged("PaginaActual"); | |
} | |
} | |
public int TotalPaginas | |
{ | |
get { return _totalPaginas; } | |
private set | |
{ | |
_totalPaginas = value; | |
OnPropertyChanged("TotalPaginas"); | |
} | |
} | |
public ICommand PrimeroCommand | |
{ | |
get { return new RelayCommand(IraPrimero, () => PaginaActual > 0); } | |
} | |
public ICommand UltimoCommand | |
{ | |
get { return new RelayCommand(IraUltimo, () => PaginaActual < TotalPaginas); } | |
} | |
public ICommand AnteriorCommand | |
{ | |
get { return new RelayCommand(IraAnterior, () => PaginaActual > 0); } | |
} | |
public ICommand SiguienteCommand | |
{ | |
get { return new RelayCommand(IraSiguiente, () => PaginaActual < TotalPaginas ); } | |
} | |
public ICommand BuscarCommand | |
{ | |
get { return new RelayCommand(Buscar); } | |
} | |
private void IraPrimero() | |
{ | |
PaginaActual = 0; | |
ActualizarLista(); | |
} | |
private void IraSiguiente() | |
{ | |
PaginaActual++; | |
ActualizarLista(); | |
} | |
private void IraAnterior() | |
{ | |
PaginaActual--; | |
ActualizarLista(); | |
} | |
private void IraUltimo() | |
{ | |
PaginaActual = TotalPaginas; | |
ActualizarLista(); | |
} | |
protected void ActualizarLista() | |
{ | |
Lista = _modelo.ObtenerPagina( | |
Constantes.TAMANIO_PAGINA, | |
PaginaActual, | |
CrearFiltro(),CrearOrden()); | |
} | |
protected abstract Func<T, object> CrearOrden(); | |
protected abstract Expression<Func<T, bool>> CrearFiltro(); | |
protected void Buscar() | |
{ | |
TotalPaginas = _modelo.ObtenerUltimaPagina( | |
Constantes.TAMANIO_PAGINA, CrearFiltro()); | |
IraPrimero(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment