public virtual ItemData <List <T> > GetAll(GenericQuerySelectors selectors) { ItemData <List <T> > result = new ItemData <List <T> >(); result.Data = GetGenericSelectorQuery(selectors).ToList(); return(result); }
public virtual PagedData <T> GetAll(GenericQuerySelectors selectors, int pageSize, int pageIndex) { PagedData <T> result = new PagedData <T>(); var query = GetGenericSelectorQuery(selectors); result.ItemsCount = query.Count(); result.PageIndex = pageIndex; result.PageSize = pageSize; result.Data = query.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList(); return(result); }
private IQueryable <T> GetGenericSelectorQuery(GenericQuerySelectors selectors) { var dbset = GetCollection().AsQueryable(); if (selectors != null) { if (selectors.Filters != null) { foreach (GenericQueryFilter filter in selectors.Filters) { if (!string.IsNullOrEmpty(filter.OpName)) { dbset = dbset.Where($"{filter.FieldName} {filter.OpName} @0", new object[] { filter.FilterValue }); } else if (!string.IsNullOrEmpty(filter.MethodName)) { dbset = dbset.Where($"{filter.FieldName}.ToLower().{filter.MethodName}(@0)", new object[] { filter.FilterValue.ToLower() }); } } } if (selectors.SortOrders != null) { foreach (GenericQuerySortOrder sortOrder in selectors.SortOrders) { if (sortOrder.OrderDirection != null && sortOrder.OrderDirection.ToLower() == "desc") { dbset = dbset.OrderBy($"{sortOrder.FieldName} desc"); } else { dbset = dbset.OrderBy($"{sortOrder.FieldName} asc"); } } } if (selectors.Includes != null) { foreach (string include in selectors.Includes) { dbset = dbset.Include(include); } } } return(dbset); }