public static int Count(ApplicationDbContext context, BadgeEntity 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_badges", 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_Badges> > Load(ApplicationDbContext context, BadgeEntity entity) { var collectionQuery = context.JGN_Badges.Where(returnWhereClause(entity)); collectionQuery = processOptionalConditions(collectionQuery, entity); if (entity.isdropdown) { return(LoadDropdownList(collectionQuery)); } else { return(LoadCompleteList(collectionQuery)); } }
private static System.Linq.Expressions.Expression <Func <JGN_Badges, bool> > returnWhereClause(BadgeEntity entity) { var where_clause = PredicateBuilder.New <JGN_Badges>(true); if (entity.id > 0) { where_clause = where_clause.And(p => p.id == entity.id); } if (entity.categoryid > 0) { where_clause = where_clause.And(p => p.category_id == entity.categoryid); } if (entity.isdeduct != 2) { where_clause = where_clause.And(p => p.isdeduct == entity.isdeduct); } if (entity.ishide != 2) { where_clause = where_clause.And(p => p.ishide == entity.ishide); } if (entity.ismultiple != 2) { where_clause = where_clause.And(p => p.ismultiple == entity.ismultiple); } return(where_clause); }
private static IQueryable <JGN_Badges> processOptionalConditions(IQueryable <JGN_Badges> collectionQuery, BadgeEntity query) { if (query.order != "") { collectionQuery = (IQueryable <JGN_Badges>)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, BadgeEntity entity) { var str = new StringBuilder(); return(key + entity.datefilter + "" + entity.type + "" + entity.categoryid + "" + UtilityBLL.ReplaceSpaceWithHyphin(entity.order.ToLower()) + "" + entity.pagenumber + "" + entity.term); }
private static int CountRecords(ApplicationDbContext context, BadgeEntity entity) { return(context.JGN_Badges.Where(returnWhereClause(entity)).Count()); }