예제 #1
0
        public static string GenerateKey(string key, AttrTemplateSectionEntity entity)
        {
            var str = new StringBuilder();

            str.AppendLine(key + "_" + "" + entity.templateid + "" + entity.attr_type + "" + entity.pagenumber + "" + entity.pagesize);


            return(str.ToString());
        }
예제 #2
0
        public static async Task <List <JGN_Attr_TemplateSections> > LoadItems(ApplicationDbContext context, AttrTemplateSectionEntity entity)
        {
            if (!entity.iscache ||
                Jugnoon.Settings.Configs.GeneralSettings.cache_duration == 0 ||
                entity.pagenumber > Jugnoon.Settings.Configs.GeneralSettings.max_cache_pages)
            {
                return(await FetchItems(context, entity));
            }
            else
            {
                string key  = GenerateKey("ld_ad_attr_temp_", entity);
                var    data = new List <JGN_Attr_TemplateSections>();
                if (!SiteConfig.Cache.TryGetValue(key, out data))
                {
                    data = await FetchItems(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, data, cacheEntryOptions);
                }
                else
                {
                    data = (List <JGN_Attr_TemplateSections>)SiteConfig.Cache.Get(key);
                }
                return(data);
            }
        }
예제 #3
0
        private static System.Linq.Expressions.Expression <Func <JGN_Attr_TemplateSections, bool> > returnWhereClause(AttrTemplateSectionEntity entity)
        {
            var where_clause = PredicateBuilder.New <JGN_Attr_TemplateSections>(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);
            }
            else
            {
                if (entity.excludedid > 0)
                {
                    where_clause = where_clause.And(p => p.id != entity.excludedid);
                }

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

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

            return(where_clause);
        }
예제 #4
0
        private static IQueryable <JGN_Attr_TemplateSections> processOptionalConditions(IQueryable <JGN_Attr_TemplateSections> collectionQuery, AttrTemplateSectionEntity query)
        {
            if (query.order != "")
            {
                collectionQuery = (IQueryable <JGN_Attr_TemplateSections>)collectionQuery.Sort(query.order);
            }
            // 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);
        }
예제 #5
0
 public static async Task <int> Count(ApplicationDbContext context, AttrTemplateSectionEntity entity)
 {
     return(await context.JGN_Attr_TemplateSections.Where(returnWhereClause(entity)).CountAsync());
 }
예제 #6
0
        private static async Task <List <JGN_Attr_TemplateSections> > FetchItems(ApplicationDbContext context, AttrTemplateSectionEntity entity)
        {
            var collectionQuery = context.JGN_Attr_TemplateSections.Where(returnWhereClause(entity));

            collectionQuery = processOptionalConditions(collectionQuery, entity);

            return(await LoadCompleteList(collectionQuery));
        }