Пример #1
0
        private OrderByClass ObtenerOrderBy(ParametrosDeQuery <T> parametrosDeQuery)
        {
            if (parametrosDeQuery.OrderBy == null && parametrosDeQuery.OrderByDescending == null)
            {
                return(new OrderByClass(x => x.Id, true));
            }

            return((parametrosDeQuery.OrderBy != null)
                ? new OrderByClass(parametrosDeQuery.OrderBy, true) :
                   new OrderByClass(parametrosDeQuery.OrderByDescending, false));
        }
Пример #2
0
        public List <T> TraerSegunParametros(ParametrosDeQuery <T> parametrosDeQuery)
        {
            var orderByClass = ObtenerOrderBy(parametrosDeQuery);
            Expression <Func <T, bool> > whereTrue = x => true;

            var where = (parametrosDeQuery.Where == null) ? whereTrue : parametrosDeQuery.Where;
            using (var db = new VentaContext())
            {
                return(db.Set <T>().Where(where).OrderByDescending(orderByClass.OrderBy).ToList());
            }
        }
Пример #3
0
        public IEnumerable <T> EncontrarPor(ParametrosDeQuery <T> parametrosDeQuery)
        {
            var orderByClass = ObtenerOrderBy(parametrosDeQuery);
            Expression <Func <T, bool> > whereTrue = x => true;

            var where = (parametrosDeQuery.Where == null) ? whereTrue : parametrosDeQuery.Where;
            using (VentaContext db = new VentaContext())
            {
                if (orderByClass.IsAscending)
                {
                    return(db.Set <T>().Where(where).OrderBy(orderByClass.OrderBy)
                           .Skip((parametrosDeQuery.Pagina - 1) * parametrosDeQuery.Top)
                           .Take(parametrosDeQuery.Top).ToList());
                }
                else
                {
                    return(db.Set <T>().Where(where).OrderByDescending(orderByClass.OrderBy)
                           .Skip((parametrosDeQuery.Pagina - 1) * parametrosDeQuery.Top)
                           .Take(parametrosDeQuery.Top).ToList());
                }
            }
        }