I'm trying to write a service layer method that will take all the necessary parameters that will allow me to get data from the repository in the way how a webforms grid would work.
The repository returns IQueryable<T>.
I came up with a model like this:
public class PagedModel<T>
{
public GridSortOptions GridSortOptions { get; set; } //Enum for ASC and DESC
public IList<T> Items { get; set; }
public int Page { get; set; }
public int PageSize { get; set; }
}
The method:
PagedModel<User> GetUsers(Expression<Func<T,bool>> predicate, int page, int pageSize, GridSortOptions sortOption);
Questions:
What I want:
I find it nice sometimes to create a "Criteria" class that contains all the properties separate from the list of items you are searching for. This way you can use it as a model property that will automatically be bound on your search actions, pass it to service and repository methods (instead of a bunch of separate params), persist it in session if need be, have strongly typed filter properties specific to the current type you are searching for (ie User), have a supertype for holding generic paging or sorting.
Something like
public class UserCriteria
{
public GridSortOptions GridSortOptions { get; set; } //Enum for ASC and DESC
public int Page { get; set; }
public int PageSize { get; set; }
public bool? IsActive { get; set; }
public string UserName { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With