Ejemplo n.º 1
0
        public ActionResult EditThread(int ThreadID)
        {
            Thread thread = _threadServices.GetThread(ThreadID);
            Post post = thread.FirstPost;

            if (!_postServices.CanEditPost(post.PostID, _currentUser.UserID))
            {
                SetError("You can't edit this post");
                return RedirectToAction("ViewThread", "Board", new { ThreadID = thread.ThreadID });
            }

            SetBreadCrumb("Edit Thread");

            var model = GenerateThreadViewModel(thread.ForumID, EditorType.Edit, post.PostID);
            return View("Thread", model);
        }
Ejemplo n.º 2
0
        public ActionResult ViewThread(int ThreadID, int?PostID, bool LastPost = false, int Page = 1)
        {
            Thread thread = _threadServices.GetThread(ThreadID);

            if (!_permissionServices.CanView(thread.ForumID, _currentUser.UserID) && thread.Type != 4)
            {
                SetNotice("You can't view this forum");
                return(RedirectToAction("Index"));
            }

            if (User.Identity.IsAuthenticated)
            {
                _threadServices.ThreadViewed(ThreadID, _currentUser.UserID);
            }

            int PostCount   = thread.Posts.Count;
            int PageSize    = int.Parse(SiteConfig.PostsPerPage.Value);
            int PageCount   = (int)Math.Ceiling(((decimal)PostCount / PageSize));
            int CurrentPage = LastPost ? PageCount : Page;

            if (PostID != null)
            {
                Post post = _postServices.GetPost(PostID.Value);
                IEnumerable <Post> AllPosts = _threadServices.GetPosts(ThreadID);
                int Position = AllPosts.ToList().IndexOf(post) + 1;
                CurrentPage = (int)Math.Ceiling(((decimal)Position / PageSize));
            }

            SetBreadCrumb(thread.Title);

            Pagination Pagination = new Pagination(CurrentPage, PostCount, PageSize, "ViewThread", "Board", new { ThreadID = ThreadID });

            int lastPostId = thread.Posts.OrderByDescending(item => item.Date).FirstOrDefault().PostID;

            IEnumerable <Post> PagedPosts = _postServices.GetPagedPosts(ThreadID, CurrentPage, PageSize);

            bool hasPermissions = _roleServices.UserHasSpecialPermissions(_currentUser.UserID, SpecialPermissionValue.Administrator, SpecialPermissionValue.Moderator);
            bool canReply       = _permissionServices.CanReply(thread.ForumID, _currentUser.UserID);

            IEnumerable <PostRow> postRows = PagedPosts.Select((x, i) => new PostRow
            {
                Post            = x,
                CurrentUser     = _currentUser,
                Thread          = thread,
                CanEdit         = hasPermissions ? true : (x.UserID == _currentUser.UserID ? _postServices.CanEditPost(x.PostID, _currentUser.UserID) : false),
                CanDelete       = hasPermissions ? true : (x.UserID == _currentUser.UserID ? _postServices.CanDeletePost(x.PostID, _currentUser.UserID) : false),
                CanPost         = canReply,
                IsLastPost      = x.PostID == lastPostId,
                IsOdd           = i % 2 != 0,
                CurrentTheme    = _currentTheme,
                IsAuthenticated = User.Identity.IsAuthenticated
            });

            var model = new ViewThreadViewModel
            {
                Thread        = thread,
                Posts         = postRows,
                Pagination    = Pagination,
                CanCastVote   = _permissionServices.CanCastVote(thread.ForumID, _currentUser.UserID),
                HasVoted      = _pollServices.HasVoted(thread.ThreadID, _currentUser.UserID),
                IsSubscribed  = _threadServices.IsSubscribed(thread.ThreadID, _currentUser.UserID),
                ThreadActions = new ThreadActions
                {
                    CanLock     = _permissionServices.CanLock(thread.ThreadID, _currentUser.UserID),
                    CurrentUser = _currentUser,
                    Thread      = thread
                },
                CurrentUser = _currentUser,
            };

            if (thread.HasPoll)
            {
                var threadPoll = new ThreadPoll()
                {
                    CanCastVote = model.CanCastVote && !model.HasVoted && !thread.IsLocked,
                    CurrentUser = _currentUser,
                    Poll        = thread.Poll
                };

                model.ThreadPoll = threadPoll;
            }

            return(View(model));
        }