public static int Count(ApplicationDbContext context, GACategoryEntity entity) { if (!entity.iscache || Jugnoon.Settings.Configs.GeneralSettings.cache_duration == 0 || entity.pagenumber > Jugnoon.Settings.Configs.GeneralSettings.max_cache_pages) { return(CountRecords(context, entity)); } else { string key = GenerateKey("cnt_ga_categories", entity); int records = 0; if (!SiteConfig.Cache.TryGetValue(key, out records)) { records = CountRecords(context, entity); var cacheEntryOptions = new MemoryCacheEntryOptions() // Keep in cache for this time, reset time if accessed. .SetSlidingExpiration(TimeSpan.FromSeconds(3600)); // Save data in cache. SiteConfig.Cache.Set(key, records, cacheEntryOptions); } else { records = (int)SiteConfig.Cache.Get(key); } return(records); } }
public static Task <List <JGN_BadgeCategories> > Load(ApplicationDbContext context, GACategoryEntity entity) { var collectionQuery = context.JGN_BadgeCategories.Where(returnWhereClause(entity)); collectionQuery = processOptionalConditions(collectionQuery, entity); return(LoadCompleteList(collectionQuery)); }
private static System.Linq.Expressions.Expression <Func <JGN_BadgeCategories, bool> > returnWhereClause(GACategoryEntity entity) { var where_clause = PredicateBuilder.New <JGN_BadgeCategories>(true); if (entity.id > 0) { where_clause = where_clause.And(p => p.id == entity.id); } // if (entity.type > 0) // where_clause = where_clause.And(p => p.type == entity.type); return(where_clause); }
private static IQueryable <JGN_BadgeCategories> processOptionalConditions(IQueryable <JGN_BadgeCategories> collectionQuery, GACategoryEntity query) { if (query.order != "") { collectionQuery = (IQueryable <JGN_BadgeCategories>)collectionQuery.Sort(query.order); } if (query.id == 0) { // validation check (if not set, it will return zero records that will make it difficult to debug the code) if (query.pagesize == 0) { query.pagesize = 18; } // 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); }
private static string GenerateKey(string key, GACategoryEntity entity) { var str = new StringBuilder(); return(key + entity.datefilter + "" + entity.type + "" + UtilityBLL.ReplaceSpaceWithHyphin(entity.order.ToLower()) + "" + entity.pagenumber + "" + entity.term); }
private static int CountRecords(ApplicationDbContext context, GACategoryEntity entity) { return(context.JGN_BadgeCategories.Where(returnWhereClause(entity)).Count()); }