Esempio n. 1
0
 public void SaveNewForum(BoardForum forum)
 {
     forum.CreateDate          = DateTime.Now;
     forum.LastPostDate        = DateTime.Now;
     forum.LastPostByAccountID = 0;
     forum.LastPostByUsername  = null;
     forum.PostCount           = 0;
     forum.ThreadCount         = 0;
     _forumRepository.SaveForum(forum);
 }
Esempio n. 2
0
        public int SaveGroup(Group group)
        {
            int result = 0;

            if (group.GroupID > 0)
            {
                result = _groupRepository.SaveGroup(group);
            }
            else
            {
                result = _groupRepository.SaveGroup(group);

                BoardForum forum = new BoardForum();
                forum.CategoryID          = 8; //group forums container
                forum.CreateDate          = DateTime.Now;
                forum.LastPostByAccountID = _webContext.CurrentUser.AccountID;
                forum.LastPostByUsername  = _webContext.CurrentUser.UserName;
                forum.LastPostDate        = DateTime.Now;
                forum.Name        = group.Name;
                forum.PageName    = group.PageName;
                forum.PostCount   = 0;
                forum.Subject     = group.Name;
                forum.ThreadCount = 0;
                forum.UpdateDate  = DateTime.Now;
                int ForumID = _forumRepository.SaveForum(forum);

                //create relationship between the group and forum
                GroupForum gf = new GroupForum();
                gf.ForumID    = ForumID;
                gf.GroupID    = group.GroupID;
                gf.CreateDate = DateTime.Now;
                _groupForumRepository.SaveGroupForum(gf);
            }

            return(result);
        }
Esempio n. 3
0
        public void Save(BoardPost post)
        {
            //is new thread
            if (_webContext.LoggedIn)
            {
                post.ReplyByAccountID = _webContext.AccountID;
                post.ReplyByUsername  = _webContext.CurrentUser.UserName;
                if (_webContext.PostID > 0)
                {
                    BoardPost postToReplyToo = _postRepository.GetPostByID(_webContext.PostID);
                    if (postToReplyToo.IsThread)
                    {
                        post.ThreadID = postToReplyToo.PostID;
                    }
                    else
                    {
                        //if post.ThreadID = postToReplyToo.ThreadID thì ở thread show tất cả bình luận.
                        post.ThreadID = postToReplyToo.PostID;
                    }
                    post.ForumID = postToReplyToo.ForumID;
                }
                else
                if (_webContext.ForumID > 0)
                {
                    post.ForumID  = _webContext.ForumID;
                    post.IsThread = _webContext.IsThread;
                    if (!_postRepository.CheckPostPageNameIsUnique(post.PageName))
                    {
                        _view.SetErrorMessage("The page name you are trying to use is already in use!");
                        return;
                    }
                }
                post.CreateDate = DateTime.Now;
                post.UpdateDate = DateTime.Now;
                post.AccountID  = _webContext.CurrentUser.AccountID;
                post.Username   = _webContext.CurrentUser.UserName;
                post.ReplyCount = 0;
                post.ViewCount  = 0;
                if (post.PageName != null)
                {
                    post.PageName = post.PageName.Replace(" ", "-");
                }
                else
                {
                    post.PageName = post.Name;
                    post.PageName = post.PageName.Replace(" ", "-");
                }

                post.PostID = _postRepository.SavePost(post);

                BoardForum forum = _forumRepository.GetForumByID(post.ForumID);
                forum.LastPostByAccountID = post.AccountID;
                forum.LastPostByUsername  = post.Username;
                _forumRepository.SaveForum(forum);
                BoardCategory category = _categoryRepository.GetCategoryByCategoryID(forum.CategoryID);
                category.LastPostByAccountID = post.AccountID;
                category.LastPostByUsername  = post.Username;
                _categoryRepository.SaveCategory(category);
                BoardPost thread;
                if (post.IsThread)
                {
                    thread = _postRepository.GetPostByID(post.PostID);
                }
                else
                {
                    thread = _postRepository.GetPostByID((long)post.ThreadID);
                }

                //is this forum part of a group?
                Group group = _groupRepository.GetGroupByForumID(forum.ForumID);

                //add an alert to the filter
                if (post.IsThread)
                {
                    //is this a group forum?
                    if (group != null)
                    {
                        _alertService.AddNewBoardThreadAlert(category, forum, thread, group);
                    }
                    else
                    {
                        _alertService.AddNewBoardThreadAlert(category, forum, thread);
                    }
                }
                else
                {
                    //is this a group forum?
                    if (group != null)
                    {
                        _alertService.AddNewBoardPostAlert(category, forum, post, thread, group);
                    }
                    else
                    {
                        _alertService.AddNewBoardPostAlert(category, forum, post, thread);
                    }
                }
                //_redirector.GoToForumsViewPost(forum.PageName, category.PageName, thread.PageName);
                if (_webContext.IsThread == false)
                {
                    _redirector.Redirect("~/Groups/ViewGroupForumPost.aspx?PostID=" + _webContext.PostID + "&GroupID=" + _webContext.GroupID);
                }
                else
                {
                    _redirector.Redirect("~/Groups/ViewGroup.aspx?GroupID=" + _webContext.GroupID);
                }
            }
            else
            {
                _redirector.GoToAccountLoginPage();
            }
        }