public IActionResult Results(string searchQuery) { var threads = _threadService.GetFilteredThreads(searchQuery); var zeroResults = (!string.IsNullOrEmpty(searchQuery) && !threads.Any()); var threadListings = threads.Select(thread => new ThreadListingModel { Id = thread.Id, Title = thread.Title, CreatedAt = thread.CreatedAt.ToString(), ModifiedAt = thread.ModifiedAt.ToString(), AuthorId = thread.User.Id, AuthorName = thread.User.UserName, AuthorImageUrl = thread.User.ProfileImageUrl, AuthorRating = thread.User.Rating, PostCount = thread.Posts.Count(), Forum = BuildForumListing(thread) }); var model = new SearchResultModel { Threads = threadListings, SearchQuery = searchQuery, EmptySerachResults = zeroResults }; return(View(model)); }
// GET : Forum /// <summary> /// Gets a Forum by its ID with all of its Threads for listing. /// If the "search query" parameter is NOT empty, filter & collect Threads accordingly. /// </summary> /// <param name="id">Int: forum ID.</param> /// <param name="searchQuery">String: user input (text to look for).</param> /// <returns>Object: a Forum's data, its Thread collection, and some of their data.</returns> public IActionResult Forum(int id, string searchQuery) { var forum = _forumEntityService.GetById(id); var threads = new List <ThreadEntity>(); //if (!string.IsNullOrEmpty(searchQuery)) //{ // threads = _threadEntityService.GetFilteredThreads(id, searchQuery).ToList(); //} //threads = forum.Threads.ToList(); threads = _threadEntityService.GetFilteredThreads(forum, searchQuery).ToList(); var threadListings = threads.Select(thread => new ThreadListingModel { Id = thread.Id, // int Title = thread.Title, Status = thread.Status, CreatedAt = thread.CreatedAt.ToString(), ModifiedAt = thread.ModifiedAt.ToString(), PostCount = thread.Posts.Count(), AuthorId = thread.User.Id, // ApplicationUser : IdentityUser<string> AuthorName = thread.User.UserName, AuthorImageUrl = thread.User.ProfileImageUrl, AuthorRating = thread.User.Rating, Forum = BuildForumListing(thread) }); var model = new ForumThreadsModel { Threads = threadListings, Forum = BuildForumListing(forum) }; return(View(model)); }