public IActionResult Create(int id) { var forum = _forumEntityService.GetById(id); var model = new NewThreadModel { ForumId = forum.Id, ForumName = forum.Title, AuthorName = User.Identity.Name // the User obj. from the current http context, // so: whoever is logged in & using the Thread Creation form is the User. }; 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)); }