public IActionResult Topic(int id, string searchQuery) { var forum = _forumService.GetById(id); ForumVM forumVM = BuildForumModel(forum); var posts = new List <Post>(); if (!string.IsNullOrEmpty(searchQuery)) { posts = _postService.GetFilteredPosts(forum, searchQuery).ToList(); } else { posts = forum.Posts.ToList(); } var postsTopicVM = posts.Select(p => new PostVM() { Id = p.Id, Title = p.Title, //AuthorId = p.Author.Id, //AuthorName = p.Author.UserName, //AuthorRating = p.Author.Rating, CreatedAt = p.CreatedAt, RepliesCount = p.Replies.Count(), Forum = BuildForumModel(p) }); ForumTopicVM topicVM = new ForumTopicVM() { Forum = forumVM, Posts = postsTopicVM }; return(View(topicVM)); }
public IActionResult Index() { if (HttpContext.Session.GetInt32("User") != null) { HttpContext.Session.Remove("forumId"); AccountDetailVM account = new AccountDetailVM(); ForumVM vm = new ForumVM(); List <Forum> forums = new List <Forum>(); forums = forumContainer.GetAll(); vm.Forums = forumConverter.ModelsToViewModels(forums); foreach (ForumDetailVM detailVM in vm.Forums) { detailVM.Creator = accountConverter.ModelToViewModel(accountContainer.GetById(detailVM.CreatorID)); } return(View(vm)); } return(RedirectToAction("Index", "Login")); }