Ejemplo n.º 1
0
        private static async Task <int> _Count(ApplicationDbContext context, ForumTopicEntity 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_frm_topics", 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);
            }
        }
Ejemplo n.º 2
0
 public static async Task <int> Count(ApplicationDbContext context, ForumTopicEntity entity)
 {
     if (entity.loadabusereports)
     {
         return(await AbuseTopics.Count(context, entity));
     }
     else
     {
         return(await _Count(context, entity));
     }
 }
Ejemplo n.º 3
0
        private static string GenerateKey(string key, ForumTopicEntity entity)
        {
            var cache = new StringBuilder();

            cache.Append(key + "_" + entity.forumid + "" + entity.userid + "" +
                         entity.month + "" + entity.year + "" + entity.datefilter + "" +
                         entity.replyid + "" + entity.isadult + "" +
                         entity.isresolved + "" + entity.type + "" +
                         entity.islocked + "" + UtilityBLL.ReplaceSpaceWithHyphin(entity.order.ToLower()) + "" + entity.pagenumber);

            return(cache.ToString());
        }
Ejemplo n.º 4
0
        private static string prepare_cache_key(string key, ForumTopicEntity vd)
        {
            var str = new StringBuilder();

            str.Append(key + "_" + vd.isfeatured + "" + vd.categoryid + "" + vd.categoryname + "" + UtilityBLL.ReplaceSpaceWithHyphin(vd.order.ToLower()) + "" + vd.pagenumber + "" + vd.pagesize);
            if (vd.category_ids.Length > 0)
            {
                foreach (var id in vd.category_ids)
                {
                    str.Append(id);
                }
            }
            return(str.ToString());
        }
Ejemplo n.º 5
0
        public static Task <List <JGN_ForumTopics> > LoadItems(ApplicationDbContext context, ForumTopicEntity entity)
        {
            if (!entity.iscache ||
                Jugnoon.Settings.Configs.GeneralSettings.cache_duration == 0 ||
                entity.pagenumber > Jugnoon.Settings.Configs.GeneralSettings.max_cache_pages)
            {
                return(Load_Raw(context, entity));
            }
            else
            {
                string key  = prepare_cache_key("lg_frm_cat_", entity);
                var    data = new List <JGN_ForumTopics>();
                if (!SiteConfig.Cache.TryGetValue(key, out data))
                {
                    data = Load_Raw(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_ForumTopics>)SiteConfig.Cache.Get(key);
                }
                return(Task.Run(() => data));
            }
        }
Ejemplo n.º 6
0
        private static System.Linq.Expressions.Expression <Func <TopicPostsEntity, bool> > returnWhereClause(ForumTopicEntity entity)
        {
            var where_clause = PredicateBuilder.New <TopicPostsEntity>(true);

            // public contents only
            where_clause = where_clause.And(p => p.topic.isenabled == 1 &&
                                            p.topic.isapproved == 1 &&
                                            p.forum.isenabled == 1 &&
                                            p.user.isenabled == 1);

            if (entity.id > 0 || entity.replyid > 0)
            {
                if (entity.singlepost)
                {
                    where_clause = where_clause.And(p => p.topic.id == entity.id);
                }
                else
                {
                    // multiple posts associated with single thread / topic
                    long _id = 0;
                    if (entity.id > 0)
                    {
                        _id = entity.id;
                    }
                    else if (entity.replyid > 0)
                    {
                        _id = entity.replyid;
                    }

                    where_clause = where_clause.And(p => p.topic.replyid == _id || p.topic.id == _id);
                }
            }

            // add search support for searching within threads
            if (entity.term != "")
            {
                where_clause = where_clause.And(p => p.topic.title.Contains(entity.term) ||
                                                p.topic.description.Contains(entity.term) ||
                                                p.user.UserName.Contains(entity.term) ||
                                                p.topic.tags.Contains(entity.term));
            }

            return(where_clause);
        }
Ejemplo n.º 7
0
        private static async Task <List <JGN_ForumTopics> > FetchItems(ApplicationDbContext context, ForumTopicEntity entity)
        {
            var collectionQuery = processOptionalConditions(prepareQuery(context, entity), entity);

            if (entity.id > 0 || !entity.issummary)
            {
                return(await LoadCompleteList(collectionQuery));
            }
            else
            {
                return(await LoadSummaryList(collectionQuery));
            }
        }
Ejemplo n.º 8
0
        public static async Task <GoogleChartEntity> GroupByDay(ApplicationDbContext context, ForumTopicEntity entity)
        {
            var reportData = await context.JGN_ForumTopics
                             .Join(context.AspNetusers,
                                   topic => topic.userid,
                                   user => user.Id,
                                   (topic, user) => new TopicUserEntity
            {
                topic = topic,
                user  = user
            })
                             .Where(ForumTopicBLL.returnWhereClause(entity))
                             .GroupBy(o => new
            {
                day = o.topic.created_at.Day
            })
                             .Select(g => new ReportEntity
            {
                Day   = g.Key.day,
                Total = g.Count()
            })
                             .OrderBy(a => a.Day)
                             .ToListAsync();

            var newObject = new { role = "style" };
            var data      = new GoogleChartEntity()
            {
                chartType = entity.chartType,
                dataTable = new List <dynamic[]>
                {
                    new dynamic[] { "Day", "Posted Blogs", newObject },
                }
            };

            data.report = reportData;
            foreach (var item in reportData)
            {
                data.dataTable.Add(new dynamic[] { item.Year.ToString(), item.Total, "color: #76A7FA" });
            }

            return(data);
        }
Ejemplo n.º 9
0
        public static async Task <GoogleChartEntity> Last12MonthsReport(ApplicationDbContext context, ForumTopicEntity entity)
        {
            var reportData = await context.JGN_ForumTopics
                             .Join(context.AspNetusers,
                                   topic => topic.userid,
                                   user => user.Id,
                                   (topic, user) => new TopicUserEntity
            {
                topic = topic,
                user  = user
            })
                             .Where(p => p.topic.created_at >= DateTime.Now.AddYears(-1))
                             .GroupBy(o => new
            {
                month = o.topic.created_at.Month,
                year  = o.topic.created_at.Year
            })
                             .Select(g => new ReportEntity
            {
                Year  = g.Key.year,
                Month = g.Key.month,
                Total = g.Count()
            })
                             .OrderBy(a => a.Year)
                             .ToListAsync();

            var newObject = new { role = "style" };
            var data      = new GoogleChartEntity()
            {
                chartType = entity.chartType,
                dataTable = new List <dynamic[]>
                {
                    new dynamic[] { "Month", "Posted Topics", newObject },
                }
            };

            foreach (var item in reportData)
            {
                data.dataTable.Add(new dynamic[] { item.Year.ToString(), item.Total, "color: #76A7FA" });
            }

            return(data);
        }
Ejemplo n.º 10
0
 private static IQueryable <TopicPostsEntity> prepareQuery(ApplicationDbContext context, ForumTopicEntity entity)
 {
     return(context.JGN_ForumTopics
            .Join(context.AspNetusers,
                  topic => topic.userid,
                  user => user.Id, (topic, user) => new { topic, user })
            .Join(context.JGN_Forums,
                  topic => topic.topic.forumid,
                  forum => forum.id, (topic, forum) =>
                  new TopicPostsEntity
     {
         forum = forum,
         topic = topic.topic,
         user = topic.user
     })
            .Where(returnWhereClause(entity)));
 }
Ejemplo n.º 11
0
        public static System.Linq.Expressions.Expression <Func <TopicUserEntity, bool> > returnWhereClause(ForumTopicEntity entity)
        {
            var where_clause = PredicateBuilder.New <TopicUserEntity>(true);

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

            if (entity.onlytopics)
            {
                where_clause = where_clause.And(p => p.topic.replyid == 0);
            }
            else if (entity.loadall)
            {
                if (entity.singlepost)
                {
                    where_clause = where_clause.And(p => p.topic.id == entity.id);
                }
                else
                {
                    where_clause = where_clause.And(p => p.topic.id == entity.id || p.topic.replyid == entity.id);
                }
            }
            else
            {
                if (entity.replyid > 0)
                {
                    where_clause = where_clause.And(p => p.topic.replyid == entity.replyid);
                }
                else if (entity.id > 0)
                {
                    where_clause = where_clause.And(p => p.topic.id == entity.id);
                }
                else
                {
                    where_clause = where_clause.And(p => p.topic.replyid == 0); // only main topics
                }
            }


            if (entity.tags != "")
            {
                foreach (var tag in entity.tags.Split(char.Parse(",")))
                {
                    where_clause = where_clause.And(p => p.topic.tags.Contains(tag));
                }
            }

            if (entity.loadabusereports)
            {
                where_clause = where_clause.And(p => p.abusereports.type == (byte)AbuseReport.Types.Forums);
            }

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

            if (entity.username != "")
            {
                where_clause = where_clause.And(p => p.user.UserName == entity.username);
            }

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

            if (entity.ispublic)
            {
                where_clause = where_clause.And(p => p.topic.isenabled == 1);
            }
            else
            {
                if (entity.isenabled != EnabledTypes.All)
                {
                    where_clause = where_clause.And(p => p.topic.isenabled == (byte)entity.isenabled);
                }

                if (entity.isapproved != ApprovedTypes.All)
                {
                    where_clause = where_clause.And(p => p.topic.isapproved == (byte)entity.isapproved);
                }
            }

            if (entity.isadult != AdultTypes.All)
            {
                where_clause = where_clause.And(p => p.topic.isadult == (byte)entity.isadult);
            }


            if (entity.isresolved != ResolvedActions.All)
            {
                where_clause = where_clause.And(p => p.topic.isresolved == (byte)entity.isresolved);
            }


            if (entity.islocked != LockedActions.All)
            {
                where_clause = where_clause.And(p => p.topic.islocked == (byte)entity.islocked);
            }

            if (entity.term != "")
            {
                where_clause = where_clause.And(p => p.topic.title.Contains(entity.term) ||
                                                p.topic.description.Contains(entity.term) ||
                                                p.user.UserName.Contains(entity.term) ||
                                                p.topic.tags.Contains(entity.term));
            }

            if (entity.month > 0 && entity.year > 0)
            {
                where_clause = where_clause.And(p => p.topic.created_at.Month == entity.month && p.topic.created_at.Year == entity.year);
            }
            else if (entity.year > 0)
            {
                where_clause = where_clause.And(p => p.topic.created_at.Year == entity.year);
            }
            else if (entity.month > 0)
            {
                where_clause = where_clause.And(p => p.topic.created_at.Month == entity.month);
            }


            if (entity.reporttype != DefaultReportTypes.None)
            {
                switch (entity.reporttype)
                {
                case DefaultReportTypes.Today:
                    where_clause = where_clause.And(p => p.topic.created_at.Date == DateTime.Now.Date);
                    break;

                case DefaultReportTypes.Yesterday:
                    where_clause = where_clause.And(p => p.topic.created_at.Date == DateTime.Now.Date.AddDays(-1));
                    break;

                case DefaultReportTypes.TodayYesterday:
                    where_clause = where_clause.And(p => p.topic.created_at.Date == DateTime.Now.Date || p.topic.created_at == DateTime.Now.Date.AddDays(-1));
                    break;

                case DefaultReportTypes.Week:
                    where_clause = where_clause.And(p => p.topic.created_at >= DateTime.Now.AddDays(-7));
                    break;

                case DefaultReportTypes.LastWeek:
                    where_clause = where_clause.And(p => p.topic.created_at.Date >= DateTime.Now.Date.AddDays(-14) && p.topic.created_at.Date <= DateTime.Now.Date.AddDays(-7));
                    break;

                case DefaultReportTypes.Month:
                    where_clause = where_clause.And(p => p.topic.created_at >= DateTime.Now.AddDays(-31));
                    break;

                case DefaultReportTypes.LastMonth:
                    where_clause = where_clause.And(p => p.topic.created_at.Date >= DateTime.Now.Date.AddMonths(-2) && p.topic.created_at.Date <= DateTime.Now.Date.AddMonths(-1));
                    break;

                case DefaultReportTypes.Year:
                    where_clause = where_clause.And(p => p.topic.created_at >= DateTime.Now.AddYears(-1));
                    break;
                }
            }

            return(where_clause);
        }
Ejemplo n.º 12
0
        public static IQueryable <TopicUserEntity> processOptionalConditions(IQueryable <TopicUserEntity> collectionQuery, ForumTopicEntity query)
        {
            if (query.order != "")
            {
                collectionQuery = (IQueryable <TopicUserEntity>)collectionQuery.Sort(query.order);
            }
            if (query.id > 0)
            {
                // validation check (if not set, it will return zero records that will make it difficult to debug the code)
                if (query.pagesize == 0)
                {
                    query.pagesize = 18;
                }
                // 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);
        }
Ejemplo n.º 13
0
 private static IQueryable <TopicUserEntity> prepareQuery(ApplicationDbContext context, ForumTopicEntity entity)
 {
     return(context.JGN_ForumTopics
            .Join(context.AspNetusers,
                  topic => topic.userid,
                  user => user.Id,
                  (topic, user) => new TopicUserEntity
     {
         topic = topic,
         user = user
     }).Where(returnWhereClause(entity)));
 }
Ejemplo n.º 14
0
 private static Task <List <JGN_ForumTopics> > Load_Raw(ApplicationDbContext context, ForumTopicEntity entity)
 {
     return(processOrder(prepareQuery(context, entity), entity)
            .Select(p => new JGN_ForumTopics
     {
         id = p.topic.id,
         forumid = p.topic.forumid,
         userid = p.topic.userid,
         title = p.topic.title,
         description = p.topic.description,
         tags = p.topic.tags,
         replies = p.topic.replies,
         isadult = p.topic.isadult,
         created_at = p.topic.created_at,
         isenabled = p.topic.isenabled,
         views = p.topic.views,
         replyid = p.topic.replyid,
         isresolved = p.topic.isresolved,
         type = p.topic.type,
         islocked = p.topic.islocked,
         isapproved = p.topic.isapproved,
         liked = p.topic.liked,
         disliked = p.topic.disliked,
         lastpostdate = p.topic.lastpostdate,
         lastpostuserid = p.topic.lastpostuserid,
         resolvedpostid = p.topic.resolvedpostid,
         author = new ApplicationUser()
         {
             firstname = p.user.firstname,
             lastname = p.user.lastname,
             picturename = p.user.picturename
         },
         forums = new JGN_Forums()
         {
             id = p.forum.id,
             title = p.forum.title,
             lastpostid = p.forum.lastpostid
         }
     }).ToListAsync());
 }
Ejemplo n.º 15
0
 public static async Task <GoogleChartEntity> LoadReport(ApplicationDbContext context, ForumTopicEntity entity)
 {
     if (entity.reporttype == DefaultReportTypes.Yearly)
     {
         return(await ForumReports.YearlyReport(context, entity));
     }
     else if (entity.reporttype == DefaultReportTypes.CurrentMonth)
     {
         return(await ForumReports.CurrentMonthReport(context, entity));
     }
     else
     {
         return(await ForumReports.Last12MonthsReport(context, entity));
     }
 }
Ejemplo n.º 16
0
 public static Task <int> Count(ApplicationDbContext context, ForumTopicEntity entity)
 {
     return(prepareQuery(context, entity).CountAsync());
 }
Ejemplo n.º 17
0
 public static Task <List <JGN_ForumTopics> > LoadItems(ApplicationDbContext context, ForumTopicEntity entity)
 {
     return(ForumTopicBLL.processOptionalConditions(prepareQuery(context, entity), entity)
            .Select(ForumTopicBLL.prepareSummaryList()).ToListAsync());
 }
Ejemplo n.º 18
0
 public static async Task <GoogleChartEntity> GenerateReport(ApplicationDbContext context, ForumTopicEntity entity)
 {
     if (entity.groupbyType == ChartGroupBy.Day)
     {
         return(await GroupByDay(context, entity));
     }
     else if (entity.groupbyType == ChartGroupBy.Month)
     {
         return(await GroupByMonth(context, entity));
     }
     else
     {
         return(await GroupByYear(context, entity));
     }
 }
Ejemplo n.º 19
0
 private static IQueryable <TopicUserEntity> prepareQuery(ApplicationDbContext context, ForumTopicEntity entity)
 {
     return(context.JGN_ForumTopics
            .Join(context.AspNetusers,
                  topic => topic.userid,
                  user => user.Id, (topic, user) => new { topic, user })
            .Join(context.JGN_AbuseReports,
                  topic => topic.topic.id,
                  abusereports => abusereports.contentid, (topic, abusereports) => new TopicUserEntity {
         topic = topic.topic, user = topic.user, abusereports = abusereports
     })
            .Where(ForumTopicBLL.returnWhereClause(entity)));
 }
Ejemplo n.º 20
0
        public static async Task <GoogleChartEntity> CurrentMonthReport(ApplicationDbContext context, ForumTopicEntity entity)
        {
            try
            {
                var reportData = await context.JGN_ForumTopics
                                 .Join(context.AspNetusers,
                                       topic => topic.userid,
                                       user => user.Id,
                                       (topic, user) => new TopicUserEntity
                {
                    topic = topic,
                    user  = user
                })
                                 .Where(p => p.topic.created_at >= DateTime.Now.AddDays(-31))
                                 .GroupBy(x => x.topic.created_at.Day)
                                 .Select(g => new ReportEntity
                {
                    Day   = g.Key,
                    Total = g.Count()
                })
                                 .OrderBy(a => a.Day)
                                 .ToListAsync();

                var newObject = new { role = "style" };
                var data      = new GoogleChartEntity()
                {
                    chartType = entity.chartType,
                    dataTable = new List <dynamic[]>
                    {
                        new dynamic[] { "Day", "Posted Topics", newObject },
                    }
                };

                foreach (var item in reportData)
                {
                    data.dataTable.Add(new dynamic[] { item.Year.ToString(), item.Total, "color: #76A7FA" });
                }

                return(data);
            }
            catch (Exception ex)
            {
                var error = ex.Message;
            }

            return(new GoogleChartEntity());
        }
Ejemplo n.º 21
0
        private static IQueryable <TopicPostsEntity> processOrder(IQueryable <TopicPostsEntity> collectionQuery, ForumTopicEntity query)
        {
            if (query.order != "")
            {
                var orderlist = query.order.Split(char.Parse(","));
                foreach (var orderItem in orderlist)
                {
                    if (orderItem.Contains("asc") || orderItem.Contains("desc"))
                    {
                        var ordersplit = query.order.Split(char.Parse(" "));
                        if (ordersplit.Length > 1)
                        {
                            collectionQuery = AddSortOption(collectionQuery, ordersplit[0], ordersplit[1]);
                        }
                    }
                    else
                    {
                        collectionQuery = AddSortOption(collectionQuery, orderItem, "");
                    }
                }
            }
            // 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);
        }
Ejemplo n.º 22
0
        public static async Task <GoogleChartEntity> GroupByMonth(ApplicationDbContext context, ForumTopicEntity entity)
        {
            var reportData = await context.JGN_ForumTopics
                             .Join(context.AspNetusers,
                                   topic => topic.userid,
                                   user => user.Id,
                                   (topic, user) => new TopicUserEntity
            {
                topic = topic,
                user  = user
            })
                             .Where(ForumTopicBLL.returnWhereClause(entity))
                             .GroupBy(o => new
            {
                month = o.topic.created_at.Month
            })
                             .Select(g => new ReportEntity
            {
                Month = g.Key.month,
                Total = g.Count()
            })
                             .OrderBy(a => a.Month)
                             .ToListAsync();

            var newObject = new { role = "style" };
            var data      = new GoogleChartEntity()
            {
                chartType = entity.chartType,
                dataTable = new List <dynamic[]>
                {
                    new dynamic[] { "Month", "Posted Blogs", newObject },
                    new dynamic[] { "Copper", 8.94, "#b87333" },
                    new dynamic[] { "Silver", 10.49, "silver" },
                    new dynamic[] { "Gold", 19.30, "gold" },
                }
            };

            data.report = reportData;
            foreach (var item in reportData)
            {
                // data.dataTable.Add(new dynamic[] { item.Year.ToString(), item.Total, "color: #76A7FA" });
            }

            return(data);
        }
Ejemplo n.º 23
0
 public static async Task <List <JGN_ForumTopics> > LoadItems(ApplicationDbContext context, ForumTopicEntity entity)
 {
     if (entity.loadabusereports)
     {
         return(await AbuseTopics.LoadItems(context, entity));
     }
     else
     {
         return(await _LoadItems(context, entity));
     }
 }