Пример #1
0
        public static async Task <int> Count(ApplicationDbContext context, AttrAttributeEntity entity)
        {
            if (!entity.iscache ||
                Jugnoon.Settings.Configs.GeneralSettings.cache_duration == 0 ||
                entity.pagenumber > Jugnoon.Settings.Configs.GeneralSettings.max_cache_pages)
            {
                return(await CountRecords(context, entity));
            }
            else
            {
                string key     = GenerateKey("cnt_atr_attr_1", entity);
                int    records = 0;
                if (!SiteConfig.Cache.TryGetValue(key, out records))
                {
                    records = await 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);
            }
        }
Пример #2
0
        public static string GenerateKey(string key, AttrAttributeEntity entity)
        {
            var str = new StringBuilder();

            str.AppendLine(key + "_" + "" + entity.sectionid + entity.term + "" + entity.type + "" + entity.attr_type + entity.pagenumber + "" + entity.pagesize);

            return(str.ToString());
        }
Пример #3
0
        private static System.Linq.Expressions.Expression <Func <JGN_Attr_Attributes, bool> > returnWhereClause(AttrAttributeEntity entity)
        {
            var where_clause = PredicateBuilder.New <JGN_Attr_Attributes>(true);

            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.sectionid > 0)
                {
                    where_clause = where_clause.And(p => p.sectionid == entity.sectionid);
                }

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

            return(where_clause);
        }
Пример #4
0
        private static IQueryable <JGN_Attr_Attributes> processOptionalConditions(IQueryable <JGN_Attr_Attributes> collectionQuery, AttrAttributeEntity query)
        {
            if (query.order != "")
            {
                collectionQuery = (IQueryable <JGN_Attr_Attributes>)collectionQuery.Sort(query.order);
            }

            // skip logic (page size filter not required in dynamic values)
            //if (query.pagenumber > 1)
            //     collectionQuery = collectionQuery.Skip(query.pagesize * (query.pagenumber - 1));
            // take logic
            //if (!query.loadall)
            //    collectionQuery = collectionQuery.Take(query.pagesize);


            return(collectionQuery);
        }
Пример #5
0
 private static async Task <int> CountRecords(ApplicationDbContext context, AttrAttributeEntity entity)
 {
     return(await context.JGN_Attr_Attributes.Where(returnWhereClause(entity)).CountAsync());
 }
Пример #6
0
        private static Task <List <JGN_Attr_Attributes> > FetchItems(ApplicationDbContext context, AttrAttributeEntity entity)
        {
            var collectionQuery = context.JGN_Attr_Attributes.Where(returnWhereClause(entity));

            collectionQuery = processOptionalConditions(collectionQuery, entity);
            return(LoadCompleteList(collectionQuery));
        }
Пример #7
0
        public static Task <List <JGN_Attr_Attributes> > LoadItems(ApplicationDbContext context, AttrAttributeEntity entity)
        {
            if (!entity.iscache ||
                Jugnoon.Settings.Configs.GeneralSettings.cache_duration == 0 ||
                entity.pagenumber > Jugnoon.Settings.Configs.GeneralSettings.max_cache_pages)
            {
                return(FetchItems(context, entity));
            }
            else
            {
                string key  = GenerateKey("ld_atr_attr_1", entity);
                var    data = new List <JGN_Attr_Attributes>();
                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_Attr_Attributes>)SiteConfig.Cache.Get(key);
                }
                return(Task.Run(() => data));
            }
        }