示例#1
0
        public IActionResult Topic(int id, string searchQuery)
        {
            var forum = _forumService.GetById(id);

            var posts = new List <Post>();

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

            var postListings = posts.Select(p => new PostListingModel()
            {
                Id           = p.Id,
                AuthorId     = p.User.Id,
                AuthorName   = p.User.UserName,
                AuthorRating = p.User.Rating.HasValue ? p.User.Rating.Value : 0,
                Title        = p.Title,
                DatePosted   = p.Created.ToString(),
                RepliesCount = p.Replies.Count(),
                Forum        = ModelHelper.BuildForumListing(p)
            });

            var model = new ForumTopicModel()
            {
                Posts = postListings,
                Forum = ModelHelper.BuildForumListing(forum)
            };

            return(View(model));
        }
        public IActionResult Results(string searchQuery)
        {
            var posts        = _postService.GetFilteredPosts(searchQuery);
            var areNoResutls = (!string.IsNullOrEmpty(searchQuery) && !posts.Any());

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

            var model = new SearchResultModel()
            {
                Posts              = postListings,
                SearchQuery        = searchQuery,
                EmptySearchResutls = areNoResutls
            };

            return(View(model));
        }