示例#1
0
文件: Topics.cs 项目: iomeone/forum-1
        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));
        }
示例#2
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));
        }
示例#3
0
文件: Topics.cs 项目: iomeone/forum-1
        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));
        }
示例#4
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));
        }