Exemplo n.º 1
0
        public static int Count(ApplicationDbContext context, AttrValueEntity 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_classified_value_1", 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);
            }
        }
Exemplo n.º 2
0
        public static string GenerateKey(string key, AttrValueEntity entity)
        {
            var str = new StringBuilder();

            str.AppendLine(key + "_" + "" + entity.term + "" + entity.contentid + "" + entity.attr_type + "" + entity.pagenumber + "" + entity.pagesize);
            if (entity.term != "")
            {
                str.AppendLine(UtilityBLL.ReplaceSpaceWithHyphin(entity.term.ToLower()));
            }

            return(str.ToString());
        }
Exemplo n.º 3
0
        public static Task <List <JGN_Attr_Values> > LoadItems(ApplicationDbContext context, AttrValueEntity 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_artist_value_1", entity);
                var    data = new List <JGN_Attr_Values>();
                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_Values>)SiteConfig.Cache.Get(key);
                }
                return(Task.Run(() => data));
            }
        }
Exemplo n.º 4
0
        private static System.Linq.Expressions.Expression <Func <JGN_Attr_Values, bool> > returnWhereClause(AttrValueEntity entity)
        {
            var where_clause = PredicateBuilder.New <JGN_Attr_Values>(true);

            where_clause = where_clause.And(p => p.attr_type == (byte)entity.attr_type);

            if (entity.id > 0)
            {
                where_clause = where_clause.And(p => p.id == entity.id);
            }

            if (!entity.nofilter)
            {
                if (entity.contentid > 0)
                {
                    where_clause = where_clause.And(p => p.contentid == entity.contentid);
                }

                if (entity.userid != "")
                {
                    where_clause = where_clause.And(p => p.userid == entity.userid);
                }

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

            return(where_clause);
        }
Exemplo n.º 5
0
        private static IQueryable <JGN_Attr_Values> processOptionalConditions(IQueryable <JGN_Attr_Values> collectionQuery, AttrValueEntity query)
        {
            if (query.order != "")
            {
                collectionQuery = (IQueryable <JGN_Attr_Values>)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);
        }
Exemplo n.º 6
0
 private static int CountRecords(ApplicationDbContext context, AttrValueEntity entity)
 {
     return(context.JGN_Attr_Values.Where(returnWhereClause(entity)).Count());
 }
Exemplo n.º 7
0
        private static Task <List <JGN_Attr_Values> > FetchItems(ApplicationDbContext context, AttrValueEntity entity)
        {
            var collectionQuery = context.JGN_Attr_Values.Where(returnWhereClause(entity));

            collectionQuery = processOptionalConditions(collectionQuery, entity);
            return(LoadCompleteList(collectionQuery));
        }