Exemplo n.º 1
0
 private static async Task <bool> update_stats(ApplicationDbContext context, string userid)
 {
     if (userid != "")
     {
         var count = BlogsBLL.Count(context, new BlogEntity()
         {
             userid   = userid,
             ispublic = true
         }).Result;
         await UserStatsBLL.Update_Field(context, userid, (short)count, "stat_blogs");
     }
     return(true);
 }
Exemplo n.º 2
0
        private static async Task <bool> UpdateStats(ApplicationDbContext context, int RecordsEffected, int ForumID, string UserName)
        {
            if (RecordsEffected > 0)
            {
                // update user total posts stats
                var total_posts = await CountRecords(context, new ForumTopicEntity()
                {
                    userid   = UserName,
                    ispublic = true
                });

                await UserStatsBLL.Update_Field(context, UserName, (short)total_posts, "stat_forum_topics");

                //update thread stats
                int threads = await CountRecords(context, new ForumTopicEntity()
                {
                    forumid    = ForumID,
                    replyid    = 0,
                    ispublic   = true,
                    onlytopics = true
                });

                ForumBLLC.Update_Value_V3(context, ForumID, "threads", threads);

                int posts = await CountRecords(context, new ForumTopicEntity()
                {
                    forumid    = ForumID,
                    replyid    = 0,
                    ispublic   = true,
                    onlytopics = false // load all
                });

                ForumBLLC.Update_Value_V3(context, ForumID, "posts", posts);
            }

            return(true);
        }
Exemplo n.º 3
0
        public static async Task <JGN_ForumTopics> Process(ApplicationDbContext context, JGN_ForumTopics entity, bool isadmin)
        {
            if (entity.id == 0)
            {
                Validation(entity);

                var _entity = new JGN_ForumTopics()
                {
                    forumid      = entity.forumid,
                    title        = UtilityBLL.processNull(entity.title, 0),
                    description  = UtilityBLL.processNull(entity.description, 0),
                    tags         = UtilityBLL.processNull(entity.tags, 0),
                    userid       = entity.userid,
                    isenabled    = entity.isenabled,
                    isapproved   = entity.isapproved,
                    created_at   = DateTime.Now,
                    replyid      = entity.replyid,
                    lastpostdate = DateTime.Now,
                    isadult      = entity.isadult
                };

                context.Entry(_entity).State = EntityState.Added;

                await context.SaveChangesAsync();

                entity = _entity;

                // update statistics
                // if topic is approved and enabled
                if (entity.isapproved == 1 && entity.isenabled == 1)
                {
                    // update user stats
                    var total_posts = await CountRecords(context, new ForumTopicEntity()
                    {
                        userid     = entity.userid,
                        isenabled  = EnabledTypes.All,
                        isapproved = ApprovedTypes.All
                    });

                    await UserStatsBLL.Update_Field(context, entity.userid, (short)total_posts, "stat_forum_topics");

                    // update post stats
                    if (entity.replyid > 0)
                    {
                        // update topic post stats
                        // e.g
                        // replies (total replies)
                        // lastpostdatetime
                        // lastpostusername
                        await Update_Topic_Stats(context, entity);

                        // no need to update posts in case of reply
                    }
                    else
                    {
                        //update thread stats
                        try
                        {
                            int threads = await CountRecords(context, new ForumTopicEntity()
                            {
                                forumid  = entity.forumid,
                                replyid  = 0,
                                ispublic = true
                            });

                            ForumBLLC.Update_Value_V3(context, entity.forumid, "threads", threads);
                        }
                        catch (Exception ex)
                        {
                            var ms = ex.Message;
                        }


                        int posts = await CountRecords(context, new ForumTopicEntity()
                        {
                            forumid    = entity.forumid,
                            replyid    = 0,
                            ispublic   = true,
                            onlytopics = false     // replyid = 0;
                        });

                        ForumBLLC.Update_Value_V3(context, entity.forumid, "posts", posts);

                        // update lastpost time, last post id (only if new topic posted
                        ForumBLLC.Update_Last_Post(context, entity.forumid, _entity.id);
                    }

                    // update points
                    //int total_points = Convert.ToInt32(UserBLL.Return_Value(entity.userid, "stat_forum_points"));
                    //total_points = total_points + Forum_Settings.TopicReplyPoints;
                    //UserBLL.Update_Field_V3(context,  entity.userid, "stat_forum_points", total_points);

                    // send notification mail to admin
                    if (!isadmin)
                    {
                        // MailProcess.Admin_New_Content_Added(context, entity.userid, "forum topic", "");
                    }
                }
            }
            else
            {
                var item = context.JGN_ForumTopics
                           .Where(p => p.id == entity.id)
                           .FirstOrDefault <JGN_ForumTopics>();

                item.forumid = entity.forumid;
                //item.title = UtilityBLL.processNull(entity.title,0);
                item.description = UtilityBLL.processNull(entity.description, 0);
                //item.tags = UtilityBLL.processNull(entity.tags, 0);
                item.isenabled  = (byte)entity.isenabled;
                item.isapproved = (byte)entity.isapproved;

                context.SaveChanges();
            }

            return(entity);
        }