예제 #1
0
        public GroupForumThread(GroupForum parent, int id, int userid, int timestamp, string caption, bool pinned, bool locked, int deletedlevel, int deleterid)
        {
            //Game.GetClientManager().OnClientDisconnect += GroupForumThread_OnClientDisconnect;
            Views         = new List <GroupForumThreadPostView>();;
            UsersOnThread = new List <GameClient>();
            ParentForum   = parent;

            Id        = id;
            UserId    = userid;
            Timestamp = timestamp;
            Caption   = caption;
            Posts     = new List <GroupForumThreadPost>();

            Pinned           = pinned;
            Locked           = locked;
            DeletedLevel     = deletedlevel;
            DeleterUserId    = deleterid;
            DeletedTimestamp = (int)NeonEnvironment.GetUnixTimestamp();

            DataTable table;

            using (Database.Interfaces.IQueryAdapter adap = NeonEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                adap.SetQuery("SELECT * FROM group_forums_thread_posts WHERE thread_id = @id");
                adap.AddParameter("id", Id);
                table = adap.getTable();
            }

            foreach (DataRow Row in table.Rows)
            {
                Posts.Add(new GroupForumThreadPost(this, Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["timestamp"]), Row["message"].ToString(), Convert.ToInt32(Row["deleted_level"]), Convert.ToInt32(Row["deleter_user_id"])));
            }


            //DataTable table;
            using (Database.Interfaces.IQueryAdapter Adap = NeonEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adap.SetQuery("SELECT * FROM group_forums_thread_views WHERE thread_id = @id");
                Adap.AddParameter("id", Id);
                table = Adap.getTable();
            }


            foreach (DataRow Row in table.Rows)
            {
                Views.Add(new GroupForumThreadPostView(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["count"])));
            }
        }
        public bool TryGetForum(int Id, out GroupForum Forum)
        {
            if ((Forum = Forums.FirstOrDefault(c => c.Id == Id)) != null)
            {
                return(true);
            }

            if (!NeonEnvironment.GetGame().GetGroupManager().TryGetGroup(Id, out Group Gp))
            {
                return(false);
            }

            if (!Gp.HasForum)
            {
                return(false);
            }

            Forum = new GroupForum(Gp);
            Forums.Add(Forum);
            return(true);
        }
        public GroupForum CreateGroupForum(Group Gp)
        {
            if (TryGetForum(Gp.Id, out GroupForum GF))
            {
                return(GF);
            }

            using (Database.Interfaces.IQueryAdapter adap = NeonEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                adap.SetQuery("REPLACE INTO group_forums_settings (group_id) VALUES (@gp)");
                adap.AddParameter("gp", Gp.Id);
                adap.RunQuery();

                adap.SetQuery("UPDATE groups SET has_forum = '1' WHERE id = @id");
                adap.AddParameter("id", Gp.Id);
                adap.RunQuery();
            }

            GF          = new GroupForum(Gp);
            Gp.HasForum = true;
            Forums.Add(GF);
            return(GF);
        }