public IEnumerable <TEntity> Buscar(Expression <Func <TEntity, bool> > condition, string orderBy = "", string sortDirection = "", int take = 0, int skip = 0)
        {
            var query = _contexto.Set <TEntity>().Where(condition);//

            if (!string.IsNullOrEmpty(orderBy))
            {
                if (!string.IsNullOrEmpty(sortDirection))
                {
                    if (sortDirection == "asc")
                    {
                        query = OrderByHelper.OrderBy(query, orderBy);
                    }
                    else
                    {
                        query = OrderByHelper.OrderByDescending(query, orderBy);
                    }

                    if (take > 0)
                    {
                        query = query.Take(take);
                    }
                    if (skip > 0)
                    {
                        query = query.Skip(skip);
                    }
                }
            }
            return(query.AsNoTracking().ToList());
        }
Exemple #2
0
        public SearchResult <ItemMonitoramentoDTO> Buscar(Expression <Func <ItemMonitoramentoDTO, bool> > condition, string orderBy = "", string sortDirection = "", int take = 0, int skip = 0)
        {
            var query        = QueryBase().Where(condition);
            int totalRecords = query.Count();

            if (!string.IsNullOrEmpty(orderBy))
            {
                if (sortDirection == "asc")
                {
                    query = OrderByHelper.OrderBy(query, orderBy);
                }
                else
                {
                    query = OrderByHelper.OrderByDescending(query, orderBy);
                }

                if (take > 0)
                {
                    query = query.Take(take);
                }
                if (skip > 0)
                {
                    query = query.Skip(skip);
                }
            }



            return(new SearchResult <ItemMonitoramentoDTO>
            {
                Itens = query.ToList(),
                TotalRecords = totalRecords,
                RecordsPerPage = take
            });
        }
        public SearchResult <TEntity> BuscaAvancada(Expression <Func <TEntity, bool> > condition, string orderBy = "", string sortDirection = "", int take = 0, int skip = 0)
        {
            var query = _contexto.Set <TEntity>().AsQueryable();

            if (condition != null)
            {
                query = query.Where(condition);
            }

            int totalRecords = query.Count();

            if (!string.IsNullOrEmpty(orderBy))
            {
                if (!string.IsNullOrEmpty(sortDirection))
                {
                    if (sortDirection == "asc")
                    {
                        query = OrderByHelper.OrderBy(query, orderBy);
                    }
                    else
                    {
                        query = OrderByHelper.OrderByDescending(query, orderBy);
                    }

                    if (take > 0)
                    {
                        query = query.Take(take);
                    }
                    if (skip > 0)
                    {
                        query = query.Skip(skip);
                    }
                }
            }
            return(new SearchResult <TEntity>
            {
                Itens = query.ToList(),
                TotalRecords = totalRecords,
                RecordsPerPage = take
            });
        }