public static int Count(ApplicationDbContext context, UserIPEntity 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_user_ipaddress", 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_User_IPLogs> > LoadItems(ApplicationDbContext context, UserIPEntity entity) { if (!entity.iscache || Configs.GeneralSettings.cache_duration == 0 || entity.pagenumber > Configs.GeneralSettings.max_cache_pages) { return(FetchItems(context, entity)); } else { string key = GenerateKey("lg_user_ipaddress_", entity); var data = new List <JGN_User_IPLogs>(); if (!SiteConfig.Cache.TryGetValue(key, out data)) { data = FetchItems(context, entity).Result; 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, data, cacheEntryOptions); } else { data = (List <JGN_User_IPLogs>)SiteConfig.Cache.Get(key); } return(Task.Run(() => data)); } }
private static System.Linq.Expressions.Expression <Func <JGN_User_IPLogs, bool> > returnWhereClause(UserIPEntity entity) { var where_clause = PredicateBuilder.New <JGN_User_IPLogs>(true); if (entity.id > 0) { where_clause = where_clause.And(p => p.id == entity.id); } if (entity.term != "") { where_clause = where_clause.And(p => p.ipaddress.Contains(entity.term)); } if (entity.userid != null && entity.userid != "") { where_clause = where_clause.And(p => p.userid == entity.userid); } return(where_clause); }
private static IQueryable <JGN_User_IPLogs> processOptionalConditions(IQueryable <JGN_User_IPLogs> collectionQuery, UserIPEntity query) { if (query.order != "") { collectionQuery = (IQueryable <JGN_User_IPLogs>)collectionQuery.Sort(query.order); } if (query.id == 0) { // 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, UserIPEntity entity) { var str = new StringBuilder(); return(key + entity.datefilter + "" + UtilityBLL.ReplaceSpaceWithHyphin(entity.order.ToLower()) + "" + entity.userid + entity.pagenumber + "" + entity.term); }
private static int CountRecords(ApplicationDbContext context, UserIPEntity entity) { return(context.JGN_User_IPLogs.Where(returnWhereClause(entity)).Count()); }
private static Task <List <JGN_User_IPLogs> > FetchItems(ApplicationDbContext context, UserIPEntity entity) { var collectionQuery = context.JGN_User_IPLogs.Where(returnWhereClause(entity)); collectionQuery = processOptionalConditions(collectionQuery, entity); return(LoadCompleteList(collectionQuery)); }