public static Task <int> Count(ApplicationDbContext context, WikiEntity entity) { if (!entity.iscache || Configs.GeneralSettings.cache_duration == 0 || entity.pagenumber > Configs.GeneralSettings.max_cache_pages) { return(CountRecords(context, entity)); } else { string key = GenerateKey("cnt_wiki", entity); int records = 0; if (!SiteConfig.Cache.TryGetValue(key, out records)) { records = CountRecords(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, records, cacheEntryOptions); } else { records = (int)SiteConfig.Cache.Get(key); } return(Task.Run(() => records)); } }
private static System.Linq.Expressions.Expression <Func <JGN_Wiki, bool> > returnWhereClause(WikiEntity entity) { var where_clause = PredicateBuilder.New <JGN_Wiki>(true); if (entity.excludedid > 0) { where_clause = where_clause.And(p => p.id != entity.excludedid); } if (entity.id > 0 && entity.detailview) { where_clause = where_clause.And(p => p.id == entity.id || p.replyid == entity.id); } else if (entity.id > 0 && !entity.detailview) { where_clause = where_clause.And(p => p.id == entity.id); } if (entity.userid != "") { where_clause = where_clause.And(p => p.userid == entity.userid); } if (entity.replyid > 0) { where_clause = where_clause.And(p => p.replyid == entity.replyid); } else if (!entity.detailview) { where_clause = where_clause.And(p => p.replyid == 0); } if (entity.term != null && entity.term != "") { where_clause = where_clause.And(p => p.term_complete.Contains(entity.term) || p.term.Contains(entity.term)); } if (entity.term_complete != null && entity.term_complete != "") { where_clause = where_clause.And(p => p.term_complete.Contains(entity.term_complete) || p.term.Contains(entity.term)); } if (entity.character != null && entity.character != "") { where_clause = where_clause.And(p => p.term_complete.StartsWith(entity.character) || p.term.StartsWith(entity.character)); } if (entity.month > 0 && entity.year > 0) { where_clause = where_clause.And(p => p.created_at.Value.Month == entity.month && p.created_at.Value.Year == entity.year); } else if (entity.year > 0) { where_clause = where_clause.And(p => p.created_at.Value.Year == entity.year); } else if (entity.month > 0) { where_clause = where_clause.And(p => p.created_at.Value.Month == entity.month); } if (entity.tags != "") { where_clause = where_clause.And(p => p.tags.Contains(entity.tags.ToString())); } return(where_clause); }
private static IQueryable <JGN_Wiki> processOptionalConditions(IQueryable <JGN_Wiki> collectionQuery, WikiEntity query) { if (query.order != "") { collectionQuery = (IQueryable <JGN_Wiki>)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, WikiEntity entity) { return(key + UtilityBLL.ReplaceSpaceWithUnderscore(entity.term_complete) + UtilityBLL.ReplaceSpaceWithUnderscore(entity.term) + "" + UtilityBLL.ReplaceSpaceWithHyphin(entity.order.ToLower()) + "" + entity.pagenumber + "" + entity.term); }
private static Task <int> CountRecords(ApplicationDbContext context, WikiEntity entity) { return(context.JGN_Wiki.Where(returnWhereClause(entity)).CountAsync()); }
private static Task <List <JGN_Wiki> > FetchItems(ApplicationDbContext context, WikiEntity entity) { var collectionQuery = context.JGN_Wiki.Where(returnWhereClause(entity)); collectionQuery = processOptionalConditions(collectionQuery, entity); if (entity.id > 0) { return(LoadCompleteList(collectionQuery)); } else if (entity.isdropdown) { return(LoadDropdownList(collectionQuery)); } else { return(LoadSummaryList(collectionQuery)); } }
public static Task <List <JGN_Wiki> > LoadItems(ApplicationDbContext context, WikiEntity 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_wiki_", entity); var data = new List <JGN_Wiki>(); 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_Wiki>)SiteConfig.Cache.Get(key); } return(Task.Run(() => data)); } }
/// <summary> /// Add Organization wiki /// </summary> public void AddWiki() { //Wiki WikiEntity = WikiEntity.CreateInstance(ArtifactNetwork, Models); WikiEntity.InitializeKnowledge(Knowledge.EntityId, 0); }