private static IQueryable <JGN_Attr_Templates> processOptionalConditions(IQueryable <JGN_Attr_Templates> collectionQuery, AttrTemplateEntity query)
        {
            if (query.order != "")
            {
                collectionQuery = (IQueryable <JGN_Attr_Templates>)collectionQuery.Sort(query.order);
            }
            // skip logic
            if (query.pagenumber > 1)
            {
                collectionQuery = collectionQuery.Skip(query.pagesize * (query.pagenumber - 1));
            }
            // take logic
            if (!query.loadall)
            {
                collectionQuery = collectionQuery.Take(query.pagesize);
            }


            return(collectionQuery);
        }
        public static Task <List <JGN_Attr_Templates> > LoadItems(ApplicationDbContext context, AttrTemplateEntity entity)
        {
            var collectionQuery = context.JGN_Attr_Templates.Where(returnWhereClause(entity));

            collectionQuery = processOptionalConditions(collectionQuery, entity);

            return(LoadCompleteList(collectionQuery));
        }
 public static int Count(ApplicationDbContext context, AttrTemplateEntity entity)
 {
     return(context.JGN_Attr_Templates.Where(returnWhereClause(entity)).Count());
 }
        private static System.Linq.Expressions.Expression <Func <JGN_Attr_Templates, bool> > returnWhereClause(AttrTemplateEntity entity)
        {
            var where_clause = PredicateBuilder.New <JGN_Attr_Templates>(true);

            where_clause = where_clause.And(p => p.attr_type == (byte)entity.attr_type);

            if (entity.excludedid > 0)
            {
                where_clause = where_clause.And(p => p.id != entity.excludedid);
            }
            if (entity.id > 0)
            {
                where_clause = where_clause.And(p => p.id == entity.id);
            }

            if (entity.nofilter)
            {
                if (entity.term != "")
                {
                    where_clause = where_clause.And(p => p.title.Contains(entity.term));
                }
            }

            return(where_clause);
        }