Пример #1
0
        public int Post()
        {
            bool newTopic = (this.topicID < 0);

            if (newTopic)
            {
                this.CreateTopic();
            }

            if (this.postID > -1)
            {
                this.UpdatePost();
            }
            else
            {
                this.CreatePost();
                if (!newTopic)
                {
                    this.IncrementReplyStats();
                }
            }

            if (this.subscribeUserToTopic)
            {
                DBGroups.GroupTopicAddSubscriber(this.topicID, this.postUserID);
            }


            return(this.postID);
        }
Пример #2
0
        private void ResetTopicSequences()
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("PostID", typeof(int));

            using (IDataReader reader = DBGroups.GroupTopicGetPosts(this.topicID))
            {
                while (reader.Read())
                {
                    DataRow row = dataTable.NewRow();
                    row["PostID"] = reader["PostID"];
                    dataTable.Rows.Add(row);
                }
            }

            int sequence = 1;

            foreach (DataRow row in dataTable.Rows)
            {
                DBGroups.GroupPostUpdateTopicSequence(
                    Convert.ToInt32(row["PostID"]),
                    sequence);
                sequence += 1;
            }
        }
Пример #3
0
        public bool UpdateTopic()
        {
            bool result = false;

            result = DBGroups.GroupTopicUpdate(
                this.topicID,
                this.groupID,
                this.subject,
                this.sortOrder,
                this.isLocked);

            if (this.groupID != this.origGroupID)
            {
                Group.DecrementTopicCount(this.origGroupID);
                Group.IncrementTopicCount(this.groupID);

                GroupTopicMovedArgs e = new GroupTopicMovedArgs();
                e.GroupId         = groupID;
                e.OriginalGroupId = origGroupID;
                OnTopicMoved(e);


                Group.RecalculatePostStats(this.origGroupID);
                Group.RecalculatePostStats(this.groupID);
            }

            return(result);
        }
Пример #4
0
        public static bool Delete(int topicId)
        {
            bool status = false;

            GroupTopic groupTopic = new GroupTopic(topicId);

            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("PostID", typeof(int));

            using (IDataReader reader = DBGroups.GroupTopicGetPosts(topicId))
            {
                while (reader.Read())
                {
                    DataRow row = dataTable.NewRow();
                    row["PostID"] = reader["PostID"];
                    dataTable.Rows.Add(row);
                }
            }

            foreach (DataRow row in dataTable.Rows)
            {
                groupTopic.DeletePost(Convert.ToInt32(row["PostID"]));
            }

            status = DBGroups.GroupTopicDelete(topicId);

            return(status);
        }
Пример #5
0
        public static DataTable GetPostsByPage(int siteId, int pageId)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("PostID", typeof(int));
            dataTable.Columns.Add("ItemID", typeof(int));
            dataTable.Columns.Add("TopicID", typeof(int));
            dataTable.Columns.Add("ModuleID", typeof(int));
            dataTable.Columns.Add("ModuleTitle", typeof(string));
            dataTable.Columns.Add("Subject", typeof(string));
            dataTable.Columns.Add("Post", typeof(string));
            dataTable.Columns.Add("ViewRoles", typeof(string));

            using (IDataReader reader = DBGroups.GroupTopicGetPostsByPage(siteId, pageId))
            {
                while (reader.Read())
                {
                    DataRow row = dataTable.NewRow();
                    row["PostID"]      = reader["PostID"];
                    row["ItemID"]      = reader["ItemID"];
                    row["ModuleID"]    = reader["ModuleID"];
                    row["TopicID"]     = reader["TopicID"];
                    row["ModuleTitle"] = reader["ModuleTitle"];
                    row["Subject"]     = reader["Subject"];
                    row["Post"]        = reader["Post"];
                    row["ViewRoles"]   = reader["ViewRoles"];

                    dataTable.Rows.Add(row);
                }
            }

            return(dataTable);
        }
Пример #6
0
 private bool IncrementReplyStats()
 {
     return(DBGroups.GroupTopicIncrementReplyStats(
                this.topicID,
                this.postUserID,
                this.mostRecentPostDate));
 }
Пример #7
0
        public bool DeletePost(int postId)
        {
            bool deleted = DBGroups.GroupPostDelete(postId);

            if (deleted)
            {
                Group.DecrementPostCount(this.groupID);
                if (this.totalReplies > 0)
                {
                    DBGroups.GroupTopicDecrementReplyStats(this.topicID);
                }
                Group group = new Group(this.groupID);

                this.moduleID = group.ModuleId;
                this.postID   = postId;

                ContentChangedEventArgs e = new ContentChangedEventArgs();
                e.IsDeleted = true;
                OnContentChanged(e);

                int topicPostCount = GroupTopic.GetPostCount(this.topicID);
                if (topicPostCount == 0)
                {
                    GroupTopic.Delete(this.topicID);
                    Group.DecrementTopicCount(this.groupID);
                }

                ResetTopicSequences();
            }


            return(deleted);
        }
Пример #8
0
        private void GetGroup(int groupId)
        {
            using (IDataReader reader = DBGroups.GetGroup(groupId))
            {
                if (reader.Read())
                {
                    this.itemID      = int.Parse(reader["ItemID"].ToString());
                    this.moduleID    = int.Parse(reader["ModuleID"].ToString());
                    this.createdDate = Convert.ToDateTime(reader["CreatedDate"]);
                    this.createdBy   = reader["CreatedByUser"].ToString();
                    this.title       = reader["Title"].ToString();
                    this.description = reader["Description"].ToString();
                    // this is to support dbs that don't have bit data type
                    string anon = reader["AllowAnonymousPosts"].ToString();
                    this.allowAnonymousPosts = (anon == "True" || anon == "1");
                    string moderated = reader["IsModerated"].ToString();
                    this.isModerated = (moderated == "True" || moderated == "1");
                    string active = reader["IsActive"].ToString();
                    this.isActive      = (active == "True" || active == "1");
                    this.sortOrder     = int.Parse(reader["SortOrder"].ToString());
                    this.postsPerPage  = int.Parse(reader["PostsPerPage"].ToString());
                    this.topicsPerPage = int.Parse(reader["TopicsPerPage"].ToString());
                    this.topicCount    = int.Parse(reader["TopicCount"].ToString());
                    this.postCount     = int.Parse(reader["PostCount"].ToString());
                    if (reader["MostRecentPostDate"] != DBNull.Value)
                    {
                        this.mostRecentPostDate = Convert.ToDateTime(reader["MostRecentPostDate"]);
                    }
                    this.mostRecentPostUser = reader["MostRecentPostUser"].ToString();

                    if (this.topicCount > this.topicsPerPage)
                    {
                        this.totalPages = this.topicCount / this.topicsPerPage;
                        int remainder = 0;
                        Math.DivRem(this.topicCount, this.topicsPerPage, out remainder);
                        if (remainder > 0)
                        {
                            this.totalPages += 1;
                        }
                    }
                    else
                    {
                        this.totalPages = 1;
                    }
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("IDataReader didn't read in Group.GetGroup");
                    }
                }
            }
        }
Пример #9
0
 public static IDataReader GetSubscriberPage(
     int groupId,
     int pageNumber,
     int pageSize,
     out int totalPages)
 {
     return(DBGroups.GetSubscriberPage(
                groupId,
                pageNumber,
                pageSize,
                out totalPages));
 }
Пример #10
0
 public static IDataReader GetPageByUser(
     int userId,
     int pageNumber,
     int pageSize,
     out int totalPages)
 {
     return(DBGroups.GetTopicPageByUser(
                userId,
                pageNumber,
                pageSize,
                out totalPages));
 }
Пример #11
0
 private bool Update()
 {
     return(DBGroups.Update(
                this.itemID,
                this.createdByUserID,
                this.title,
                this.description,
                this.isModerated,
                this.isActive,
                this.sortOrder,
                this.postsPerPage,
                this.topicsPerPage,
                this.allowAnonymousPosts));
 }
Пример #12
0
        private void GetPost(int postId)
        {
            using (IDataReader reader = DBGroups.GroupTopicGetPost(postId))
            {
                if (reader.Read())
                {
                    this.postID      = Convert.ToInt32(reader["PostID"]);
                    this.postUserID  = Convert.ToInt32(reader["UserID"]);
                    this.postSubject = reader["Subject"].ToString();
                    this.postMessage = reader["Post"].ToString();

                    // this is to support dbs that don't have bit data type
                    string approved = reader["Approved"].ToString();
                    this.isApproved = (approved == "True" || approved == "1");
                }
            }
        }
Пример #13
0
        public DataTable GetPostIdList()
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("PostID", typeof(int));

            using (IDataReader reader = DBGroups.GroupTopicGetPosts(this.topicID))
            {
                while (reader.Read())
                {
                    DataRow row = dataTable.NewRow();
                    row["PostID"] = reader["PostID"];
                    dataTable.Rows.Add(row);
                }
            }

            return(dataTable);
        }
Пример #14
0
        private bool CreateTopic()
        {
            int newID = -1;

            newID = DBGroups.GroupTopicCreate(
                this.groupID,
                this.postSubject,
                this.sortOrder,
                this.isLocked,
                this.postUserID,
                DateTime.UtcNow);


            this.topicID = newID;
            Group.IncrementTopicCount(this.groupID);

            return(newID > -1);
        }
Пример #15
0
        private bool UpdatePost()
        {
            bool result = false;

            result = DBGroups.GroupPostUpdate(
                this.postID,
                this.postSubject,
                this.postMessage,
                this.sortOrder,
                this.isApproved);

            //IndexHelper.IndexItem(this);
            if (result)
            {
                ContentChangedEventArgs e = new ContentChangedEventArgs();
                OnContentChanged(e);
            }

            return(result);
        }
Пример #16
0
        private bool Create()
        {
            int newID = -1;

            newID = DBGroups.Create(
                this.moduleID,
                this.createdByUserID,
                this.title,
                this.description,
                this.isModerated,
                this.isActive,
                this.sortOrder,
                this.postsPerPage,
                this.topicsPerPage,
                this.allowAnonymousPosts);

            this.itemID = newID;

            return(newID > -1);
        }
Пример #17
0
        private bool CreatePost()
        {
            int  newID    = -1;
            bool approved = false;

            if (
                (ConfigurationManager.AppSettings["PostsApprovedByDefault"] != null) &&
                (string.Equals(ConfigurationManager.AppSettings["PostsApprovedByDefault"], "true", StringComparison.InvariantCultureIgnoreCase))
                )
            {
                approved = true;
            }

            this.mostRecentPostDate = DateTime.UtcNow;
            newID = DBGroups.GroupPostCreate(
                this.topicID,
                this.postSubject,
                this.postMessage,
                approved,
                this.PostUserId,
                this.mostRecentPostDate);

            this.postID = newID;
            Group.IncrementPostCount(this.groupID, this.postUserID, this.mostRecentPostDate);
            SiteUser.IncrementTotalPosts(this.postUserID);
            //IndexHelper.IndexItem(this);

            bool result = (newID > -1);

            if (result)
            {
                ContentChangedEventArgs e = new ContentChangedEventArgs();
                OnContentChanged(e);
            }

            return(result);
        }
Пример #18
0
 public static int GetPostCount(int topicId)
 {
     return(DBGroups.GroupTopicGetPostCount(topicId));
 }
Пример #19
0
 /// <summary>
 /// passing in -1 for userId will update the stats of all users.
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static bool UpdateUserStats(int userId)
 {
     return(DBGroups.UpdateUserStats(userId));
 }
Пример #20
0
 public static bool UnsubscribeAll(int userId)
 {
     return(DBGroups.GroupTopicUnsubscribeAll(userId));
 }
Пример #21
0
 public static bool Unsubscribe(int topicId, int userId)
 {
     return(DBGroups.GroupTopicUNSubscribe(topicId, userId));
 }
Пример #22
0
        private void GetTopic(int topicId)
        {
            using (IDataReader reader = DBGroups.GroupTopicGetTopic(topicId))
            {
                if (reader.Read())
                {
                    this.topicID = int.Parse(reader["TopicID"].ToString());
                    if (reader["GroupID"] != DBNull.Value)
                    {
                        this.groupID = this.origGroupID = int.Parse(reader["GroupID"].ToString());
                    }
                    if (reader["TopicDate"] != DBNull.Value)
                    {
                        this.topicDate = Convert.ToDateTime(reader["TopicDate"].ToString());
                    }
                    this.startedBy = reader["StartedBy"].ToString();
                    if (reader["StartedByUserID"] != DBNull.Value)
                    {
                        this.startedByUserID = int.Parse(reader["StartedByUserID"].ToString());
                    }

                    this.subject = reader["TopicTitle"].ToString();
                    if (reader["TotalViews"] != DBNull.Value)
                    {
                        this.totalViews = Convert.ToInt32(reader["TotalViews"]);
                    }

                    if (reader["TotalReplies"] != DBNull.Value)
                    {
                        this.totalReplies = Convert.ToInt32(reader["TotalReplies"]);
                    }

                    if (reader["SortOrder"] != DBNull.Value)
                    {
                        this.sortOrder = Convert.ToInt32(reader["SortOrder"]);
                    }
                    if (reader["GroupSequence"] != DBNull.Value)
                    {
                        this.groupSequence = Convert.ToInt32(reader["GroupSequence"]);
                    }

                    if (reader["PostsPerPage"] != DBNull.Value)
                    {
                        this.postsPerPage = Convert.ToInt32(reader["PostsPerPage"]);
                    }

                    if (this.totalReplies + 1 > this.postsPerPage)
                    {
                        this.totalPages = this.totalReplies / this.postsPerPage;
                        int remainder = 0;
                        int pageCount = Math.DivRem(this.totalReplies + 1, this.postsPerPage, out remainder);
                        if ((remainder > 0) || (pageCount > this.totalPages))
                        {
                            this.totalPages += 1;
                        }
                    }
                    else
                    {
                        this.totalPages = 1;
                    }

                    // this is to support dbs that don't have bit data type
                    string locked = reader["IsLocked"].ToString();
                    this.isLocked = (locked == "True" || locked == "1");

                    if (reader["MostRecentPostDate"] != DBNull.Value)
                    {
                        this.mostRecentPostDate = Convert.ToDateTime(reader["MostRecentPostDate"]);
                    }

                    this.mostRecentPostUser = reader["MostRecentPostUser"].ToString();

                    if (reader["MostRecentPostUserID"] != DBNull.Value)
                    {
                        this.mostRecentPostUserID = Convert.ToInt32(reader["MostRecentPostUserID"]);
                    }
                }
            }
        }
Пример #23
0
 public static bool DeleteSubscription(int subscriptionId)
 {
     return(DBGroups.DeleteSubscription(subscriptionId));
 }
Пример #24
0
 public IDataReader GetPostsReverseSorted()
 {
     return(DBGroups.GroupTopicGetPostsReverseSorted(this.topicID));
 }
Пример #25
0
 public IDataReader GetPosts()
 {
     return(DBGroups.GroupTopicGetPosts(this.topicID));
 }
Пример #26
0
 public IDataReader GetPosts(int pageNumber)
 {
     return(DBGroups.GroupTopicGetPosts(this.topicID, pageNumber));
 }
Пример #27
0
 public bool UpdateTopicViewStats()
 {
     return(DBGroups.GroupTopicUpdateViewStats(this.topicID));
 }
Пример #28
0
 public DataSet GetTopicSubscribers()
 {
     return(DBGroups.GroupTopicGetSubscribers(this.groupID, this.topicID, this.postUserID));
 }
Пример #29
0
 public static bool IsSubscribed(int topicId, int userId)
 {
     return(DBGroups.GroupTopicSubscriptionExists(topicId, userId));
 }
Пример #30
0
 public IDataReader GetPostsForRss()
 {
     return(DBGroups.GroupTopicGetPostsForRss(SiteId, PageId, ModuleId, ItemId, TopicId, MaximumDays));
 }