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)); }
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)); }