コード例 #1
0
        public IActionResult Topic(int id, string searchQuery)
        {
            var forum     = _forumService.GetById(id);
            var posts     = _forumService.GetFilteredPosts(id, searchQuery).ToList();
            var noResults = (!string.IsNullOrEmpty(searchQuery) && !posts.Any());

            var postListings = posts.Select(post => new PostListingModel
            {
                Id           = post.Id,
                Forum        = BuildForumListing(post),
                Author       = post.User.UserName,
                AuthorId     = post.User.Id,
                AuthorRating = post.User.Rating,
                Title        = post.Title,
                DatePosted   = post.Created.ToString(CultureInfo.InvariantCulture),
                RepliesCount = post.Replies.Count()
            }).OrderByDescending(post => post.DatePosted);

            var model = new TopicResultModel
            {
                EmptySearchResults = noResults,
                Posts       = postListings,
                SearchQuery = searchQuery,
                Forum       = BuildForumListing(forum)
            };

            return(View(model));
        }
コード例 #2
0
        // Get Forum
        public IActionResult Topic(int id, string searchQuery)
        {
            var forum = _forumService.GetById(id);
            // var posts = _postsService.GetPostsByForum(id); // get the Posts from particular Forum
            //var posts = forum.Posts;
            var posts     = _forumService.GetFilteredPosts(id, searchQuery).ToList();
            var noResults = (!string.IsNullOrEmpty(searchQuery) && !posts.Any());

            var postListings = posts.Select(post => new PostListingModel
            {
                Id           = post.Id,
                AuthorId     = post.User.Id,
                AuthorRating = post.User.Rating,
                AuthorName   = post.User.UserName,
                Title        = post.Title,
                DatePosted   = post.Created.ToString(),
                RepliesCount = post.Replies.Count(),
                Forum        = BuildForumListing(post)
            });

            var model = new ForumTopicModel
            {
                EmptySearchResults = noResults,
                SearchQuery        = searchQuery,
                Posts = postListings,
                Forum = BuildForumListing(forum)
            };

            return(View(model));
        }
コード例 #3
0
        public IActionResult Topic(int id, string searchQuery)
        {
            var forum = _forumService.GetById(id);
            //var posts = new List<Post>();
            var posts     = _forumService.GetFilteredPosts(id, searchQuery).ToList();
            var noResults = (!string.IsNullOrEmpty(searchQuery) && !posts.Any());

            //if (!String.IsNullOrEmpty(searchQuery))
            //{
            posts = _postService.GetFilteredPosts(forum, searchQuery).ToList();
            //}
            //posts = forum.Posts.ToList();

            var postListings = posts.Select(post => new PostListingModel
            {
                Id           = post.Id,
                AuthorId     = post.User.Id,
                AuthorRating = post.User.Rating,
                AuthorName   = post.User.UserName,
                Title        = post.Subject,
                DatePosted   = post.Created.ToString(),
                RepliesCount = post.Replies.Count(),
                Forum        = BuildForumListing(post)
            }).OrderByDescending(post => post.DatePosted);

            var model = new ForumTopicModel
            {
                Posts              = postListings,
                Forum              = BuildForumListing(forum),
                SearchQuery        = searchQuery,
                EmptySearchResults = noResults
            };

            return(View(model));
        }