/// <summary> /// Adds a new "Post" object to the ID-d parent "Thread" object. /// </summary> /// <param name="id">Integer: the ID of the parent "Thread" object.</param> /// <returns>View model data: for showing the post-creation page.</returns> public async Task <IActionResult> Create(int id) { var thread = _threadEntityService.GetById(id); var user = await _userManager.FindByNameAsync(User.Identity.Name); var model = new NewPostModel { ThreadContent = thread.Content, ThreadTitle = thread.Title, ThreadId = thread.Id, AuthorId = user.Id, AuthorName = User.Identity.Name, AuthorImageUrl = user.ProfileImageUrl, AuthorRating = user.Rating, IsAuthorAdmin = User.IsInRole("Admin"), ForumId = thread.Forum.Id, ForumTitle = thread.Forum.Title, CreatedAt = DateTime.Now }; return(View(model)); }
// TODO: if User IS NOT authen. & author., Thread-editing and cretion should not even be offered. // GET : Thread /// <summary> /// Gets a "Microsoft.AspNetCore.Mvc.ViewResult" object that renders a View to the response. /// The MVC framework will look for a View called "Index" in a folder called "Thread". /// </summary> /// <param name="id">Int: a forum's ID.</param> /// <returns>ThreadIndexModel object: a thread and its posts.</returns> public IActionResult Index(int id) { var thread = _threadEntityService.GetById(id); var posts = BuildThreadReplies(thread.Posts); var model = new ThreadIndexModel { Id = thread.Id, Title = thread.Title, Content = thread.Content, CreatedAt = thread.CreatedAt, ModifiedAt = thread.ModifiedAt, AuthorId = thread.User.Id, AuthorName = thread.User.UserName, AuthorImageUrl = thread.User.ProfileImageUrl, AuthorRating = thread.User.Rating, Posts = posts, ForumId = thread.Forum.Id, ForumName = thread.Forum.Title, IsAuthorAdmin = IsAuthorAdmin(thread.User) }; return(View(model)); }