public IActionResult ViewForum(int Id) { TblForums _TblForums = UnitOfWork.Repository <DevelopersHub.Models.TblForums>().Get(x => x.Id == Id); _TblForums.M = UnitOfWork.Repository <DevelopersHub.Models.TblMembers>().Get(x => x.Id == _TblForums.Id); List <TblForumsThreads> _list_TblForumsThreads = UnitOfWork.Repository <DevelopersHub.Models.TblForumsThreads>().GetAll(x => x.Fid == Id).ToList(); List <ForumsThreads> _list_ForumsThreads = new List <ViewModels.ForumsThreads>(); for (int i = 0; i < _list_TblForumsThreads.Count; i++) { if (_list_ForumsThreads.Find(x => x.Id == _list_TblForumsThreads[i].Id) == null) { ForumsThreads _ForumsThreads = new ForumsThreads(); _ForumsThreads.Fid = _list_TblForumsThreads[i].Fid; _ForumsThreads.Ftid = _list_TblForumsThreads[i].Ftid; _ForumsThreads.Id = _list_TblForumsThreads[i].Id; _ForumsThreads.Mid = _list_TblForumsThreads[i].Mid; _ForumsThreads.Text = _list_TblForumsThreads[i].Text; _list_ForumsThreads.Add(_ForumsThreads); } else { continue; } for (int j = i; j < _list_TblForumsThreads.Count; j++) { if (_list_TblForumsThreads[i].Id == _list_TblForumsThreads[j].Ftid) { ForumsThreads _ForumsThreads = new ForumsThreads(); _ForumsThreads.Fid = _list_TblForumsThreads[j].Fid; _ForumsThreads.Ftid = _list_TblForumsThreads[j].Ftid; _ForumsThreads.Id = _list_TblForumsThreads[j].Id; _ForumsThreads.Mid = _list_TblForumsThreads[j].Mid; _ForumsThreads.Text = _list_TblForumsThreads[j].Text; _list_ForumsThreads.Add(_ForumsThreads); } } } ViewForumViewModel _ViewForumViewModel = new ViewForumViewModel(); _ViewForumViewModel.Forum = _TblForums; _ViewForumViewModel.ForumThreads = _list_ForumsThreads; return(View(_ViewForumViewModel)); }
public ActionResult ViewForum(int ForumID, int Page = 1, bool LastPost = false) { Forum forum = _forumServices.GetForum(ForumID); UserPermissions userPermissions = _permissionServices.GetUserPermissions(forum.ForumID, _currentUser.UserID); if (!userPermissions.Visible) { SetNotice("You can't view this forum"); return(RedirectToAction("Index", "Board")); } int threadCount = forum.Threads.Count; int pageSize = SiteConfig.ThreadsPerPage.ToInt(); int pageCount = (int)Math.Ceiling(((decimal)threadCount / pageSize)); int currentPage = LastPost ? pageCount : Page; SetBreadCrumb(forum.Name); Pagination forumPagination = new Pagination(currentPage, threadCount, pageSize, "ViewForum", "Board", new { ForumID = ForumID }); IEnumerable <Thread> forumThreads = _threadServices.GetPagedThreads(ForumID, currentPage, pageSize).Where(y => y.Type != 4); IEnumerable <ThreadRow> threadRows = forumThreads.ToList().Select((thread, index) => new ThreadRow { IsOdd = index % 2 != 0, Thread = thread, TotalPosts = thread.Posts.Count, FirstPost = thread.FirstPost, LastPost = thread.Posts.OrderByDescending(post => post.Date).FirstOrDefault(), CurrentUser = _currentUser, HasNewPost = Request.IsAuthenticated ? _threadServices.HasNewPost(thread.ThreadID, _currentUser.UserID) : false, IsSubscribed = Request.IsAuthenticated ? _threadServices.IsSubscribed(thread.ThreadID, _currentUser.UserID) : false, HasAttachment = _threadServices.HasAttachment(thread.ThreadID) }); IEnumerable <Thread> globalAnnouncements = _threadServices.GetGlobalAnnouncements(); IEnumerable <ThreadRow> gaThreads = globalAnnouncements.Select((thread, index) => new ThreadRow { IsOdd = index % 2 != 0, Thread = thread, TotalPosts = thread.Posts.Count, FirstPost = thread.FirstPost, LastPost = thread.Posts.OrderByDescending(post => post.Date).FirstOrDefault(), CurrentUser = _currentUser, HasNewPost = Request.IsAuthenticated ? _threadServices.HasNewPost(thread.ThreadID, _currentUser.UserID) : false, IsSubscribed = Request.IsAuthenticated ? _threadServices.IsSubscribed(thread.ThreadID, _currentUser.UserID) : false }); ViewForumViewModel viewForum = new ViewForumViewModel() { Forum = forum, ThreadRows = threadRows.ToList(), GlobalAnnouncements = gaThreads.ToList(), Pagination = forumPagination, UserPermissions = userPermissions }; return(View(viewForum)); }