public override Task <IEnumerable <TEntity> > GetAllAsync(IParent?parent, IView <TEntity> view) { var dataQuery = GetListForParent(parent).AsQueryable(); dataQuery = view.ApplyDataView(dataQuery); if (view.SearchTerm != null) { var stringProperties = typeof(TEntity).GetProperties().Where(x => x.PropertyType == typeof(string)).ToList(); // this is not a very fast or sensible search function, but it's just an example that works for all entities dataQuery = dataQuery .Where(x => stringProperties .Any(property => (property.GetValue(x) as string) != null ? ((string)property.GetValue(x) !).Contains(view.SearchTerm, StringComparison.InvariantCultureIgnoreCase) : false)); } dataQuery = view.ApplyOrder(dataQuery); var dataQueryResult = dataQuery .Skip(view.Skip) .Take(view.Take + 1) .ToList(); var data = dataQueryResult .Take(view.Take); view.HasMoreData(dataQueryResult.Count > view.Take); return(Task.FromResult(data)); }
public override Task <IEnumerable <TCmsEntity> > GetAllAsync(IParent?parent, IView <TEntity> view) { var dataQuery = GetListForParent(parent).AsQueryable(); dataQuery = view.ApplyDataView(dataQuery); if (view.SearchTerm != null) { // this is not a very useful search function, but it's just an example dataQuery = dataQuery.Where(x => x.Id == null ? false : x.Id.Contains(view.SearchTerm)); } dataQuery = view.ApplyOrder(dataQuery); var data = dataQuery .Skip(view.Skip) .Take(view.Take) .ToList() .Select(x => _converter.Convert((TEntity)x.Clone())); view.HasMoreData(GetListForParent(parent).Count > (view.Skip + view.Take)); return(Task.FromResult(data)); }