Ejemplo n.º 1
0
        public IActionResult Index(int id = 0, int unread = 0)
        {
            var boardRoles = RoleRepository.BoardRoles.Where(r => r.BoardId == id).Select(r => r.RoleId).ToList();

            if (!UserContext.IsAdmin && boardRoles.Any() && !boardRoles.Intersect(UserContext.Roles).Any())
            {
                throw new HttpForbiddenError();
            }

            var sidebar = new ViewModels.Sidebar {
                Birthdays     = AccountRepository.GetBirthdaysList().ToArray(),
                OnlineUsers   = AccountRepository.GetOnlineList(),
                Notifications = NotificationRepository.Index()
            };

            var page          = 1;
            var topicPreviews = TopicRepository.GetPreviews(id, page, unread);

            var boardRecord = id == 0 ? null : BoardRepository.FirstOrDefault(record => record.Id == id);

            var viewModel = new PageModels.TopicIndexPage {
                BoardId      = id,
                BoardName    = boardRecord?.Name ?? "All Topics",
                Page         = page,
                Topics       = topicPreviews,
                UnreadFilter = unread,
                Sidebar      = sidebar
            };

            return(ForumViewResult.ViewResult(this, viewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(int id = 0, int page = 1, int unread = 0)
        {
            var topicIds = await TopicRepository.GetIndexIds(id, page, unread);

            var morePages = true;

            if (topicIds.Count < UserContext.ApplicationUser.TopicsPerPage)
            {
                morePages = false;
            }

            var topicPreviews = await TopicRepository.GetPreviews(topicIds);

            var boardRecords = await BoardRepository.Records();

            var boardRecord = id == 0 ? null : boardRecords.FirstOrDefault(item => item.Id == id);

            var viewModel = new ViewModels.Topics.TopicIndexPage {
                BoardId      = id,
                BoardName    = boardRecord?.Name ?? "All Topics",
                CurrentPage  = page,
                Topics       = topicPreviews,
                UnreadFilter = unread,
                MorePages    = morePages
            };

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Index(int id = 0, int pageId = 1, int unread = 0)
        {
            var messageIds = await TopicRepository.GetIndexIds(id, pageId, unread);

            var morePages = true;

            if (messageIds.Count < UserContext.ApplicationUser.TopicsPerPage)
            {
                morePages = false;
            }

            var topicPreviews = await TopicRepository.GetPreviews(messageIds);

            var boardRecord = id == 0 ? null : (await BoardRepository.Records()).FirstOrDefault(record => record.Id == id);

            var viewModel = new PageModels.TopicIndexPage {
                BoardId      = id,
                BoardName    = boardRecord?.Name ?? "All Topics",
                CurrentPage  = pageId,
                Topics       = topicPreviews,
                UnreadFilter = unread,
                MorePages    = morePages
            };

            return(await ForumViewResult.ViewResult(this, viewModel));
        }
Ejemplo n.º 4
0
        public IActionResult MergeMore(int id, int page = 0)
        {
            var record = DbContext.Messages.FirstOrDefault(item => item.Id == id);

            if (record is null)
            {
                throw new HttpNotFoundError();
            }

            var topicPreviews = TopicRepository.GetPreviews(0, page, 0);

            foreach (var topicPreview in topicPreviews.ToList())
            {
                if (topicPreview.Id == id)
                {
                    topicPreviews.Remove(topicPreview);
                }
                else
                {
                    topicPreview.SourceId = id;
                }
            }

            var viewModel = new PageModels.TopicIndexMorePage {
                More   = topicPreviews.Any(),
                Page   = page,
                Topics = topicPreviews
            };

            return(ForumViewResult.ViewResult(this, viewModel));
        }
Ejemplo n.º 5
0
        public IActionResult Merge(int id)
        {
            var record = DbContext.Messages.FirstOrDefault(item => item.Id == id);

            if (record is null)
            {
                throw new HttpNotFoundError();
            }

            var topicPreviews = TopicRepository.GetPreviews(0, 1, 0);

            foreach (var topicPreview in topicPreviews.ToList())
            {
                if (topicPreview.Id == id)
                {
                    topicPreviews.Remove(topicPreview);
                }
                else
                {
                    topicPreview.SourceId = id;
                }
            }

            var viewModel = new PageModels.TopicIndexPage {
                SourceId  = id,
                BoardName = "Pick a Destination Topic",
                BoardId   = 0,
                Page      = 1,
                Topics    = topicPreviews,
            };

            return(ForumViewResult.ViewResult(this, viewModel));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Bookmarks()
        {
            var messageIds    = (await BookmarkRepository.Records()).Select(r => r.MessageId).ToList();
            var topicPreviews = await TopicRepository.GetPreviews(messageIds);

            var viewModel = new PageModels.TopicBookmarksPage {
                Topics = topicPreviews
            };

            return(await ForumViewResult.ViewResult(this, viewModel));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Merge(int id, int page = 1)
        {
            var sourceTopic = DbContext.Topics.FirstOrDefault(item => item.Id == id);

            if (sourceTopic is null || sourceTopic.Deleted)
            {
                throw new HttpNotFoundError();
            }

            var topicIds = await TopicRepository.GetIndexIds(0, page, 0);

            var morePages = true;

            if (topicIds.Count < UserContext.ApplicationUser.TopicsPerPage)
            {
                morePages = false;
            }

            var topicPreviews = await TopicRepository.GetPreviews(topicIds);

            foreach (var topicPreview in topicPreviews.ToList())
            {
                if (topicPreview.Id == id)
                {
                    // Exclude the source topic
                    topicPreviews.Remove(topicPreview);
                }
                else
                {
                    // Mark the source topic for all target topics.
                    topicPreview.SourceId = id;
                }
            }

            var viewModel = new ViewModels.Topics.TopicIndexPage {
                SourceId    = id,
                BoardName   = "Pick a Destination Topic",
                BoardId     = 0,
                CurrentPage = page,
                Topics      = topicPreviews,
                MorePages   = morePages
            };

            return(View(viewModel));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Merge(int id, int pageId = 1)
        {
            var record = DbContext.Messages.FirstOrDefault(item => item.Id == id);

            if (record is null)
            {
                throw new HttpNotFoundError();
            }

            var messageIds = await TopicRepository.GetIndexIds(0, pageId, 0);

            var morePages = true;

            if (messageIds.Count < UserContext.ApplicationUser.TopicsPerPage)
            {
                morePages = false;
            }

            var topicPreviews = await TopicRepository.GetPreviews(messageIds);

            foreach (var topicPreview in topicPreviews.ToList())
            {
                if (topicPreview.Id == id)
                {
                    topicPreviews.Remove(topicPreview);
                }
                else
                {
                    topicPreview.SourceId = id;
                }
            }

            var viewModel = new PageModels.TopicIndexPage {
                SourceId    = id,
                BoardName   = "Pick a Destination Topic",
                BoardId     = 0,
                CurrentPage = pageId,
                Topics      = topicPreviews,
                MorePages   = morePages
            };

            return(await ForumViewResult.ViewResult(this, viewModel));
        }
Ejemplo n.º 9
0
        public IActionResult IndexMore(int id = 0, int page = 0, int unread = 0)
        {
            var boardRoles = RoleRepository.BoardRoles.Where(r => r.BoardId == id).Select(r => r.RoleId).ToList();

            if (!UserContext.IsAdmin && boardRoles.Any() && !boardRoles.Intersect(UserContext.Roles).Any())
            {
                throw new HttpForbiddenError();
            }

            var topicPreviews = TopicRepository.GetPreviews(id, page, unread);

            var viewModel = new PageModels.TopicIndexMorePage {
                More   = topicPreviews.Any(),
                Page   = page,
                Topics = topicPreviews
            };

            return(ForumViewResult.ViewResult(this, viewModel));
        }