//Get:/Forum/Topic/{id} public async Task <IActionResult> Topic(int id) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var forum = await _forumService.GetForumWithPostsAsync(id); var posts = await _PostService.GetPostsPerForumAsync(id); var forumListing = BuildForumListing(forum); var postListing = posts.Select(post => new PostListingModel { Id = post.Id, Author = post.User.UserName, AuthorRating = post.User.Rating.ToString(), Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post), }); var forumVm = new ForumTopicModel { Forum = forumListing, Posts = postListing, }; return(View(forumVm)); }
//Return a forum and associated posts identified by its primary key public IActionResult Topic(int id, string searchQuery) { Data.Models.Forum forum = _forumService.GetById(id); IEnumerable <Post> posts = new List <Post>(); //IEnumerable<Post> posts = _postService.GetPostsbyForum(id); //Refactored: //Get all the posts from the forum, then enumerate them to a list, //Then provide them to the viewModel //Nb nullOrEmpty strings checked in method posts = _postService.GetFilteredPosts(forum, searchQuery).ToList(); var postListings = posts.Select(post => new PostListingModel { Id = post.Id, AuthorName = post.User.UserName, AuthorId = post.User.Id, AuthorRating = post.User.Rating, Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post) }); var model = new ForumTopicModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Topic(int id) { var forum = _forumService.GetById(id); // grab a frum that matches the id passed // retrieve post from the DB that corresponds to this(forum-> id) particular forum /*var posts = _postService.GetPostsByForum(id);*/ var posts = forum.Posts; // collection of posts var postListing = posts.Select(post => new PostListingViewModel { Id = post.Id, AuthorId = post.User.Id, AuthorRating = post.User.Rating, Author = post.User.UserName, Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post), }); var model = new ForumTopicModel { Posts = postListing, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Post(int Id) { var forum = _forumService.GetById(Id); var posts = forum.Posts; var postListing = posts.Select(post => new PostListingModel { Id = post.Id, AuthorId = post.User.Id, AuthorRating = post.User.Rating, Title = post.Title, Created = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post) }); var model = new ForumTopicModel { Forum = BuildForumListing(forum), PostLists = postListing }; return(View(model)); }
// find specific forum using id #region for forum Topic public IActionResult Topic(int id, string searchQuery) { var forum = _forumService.GetById(id); var posts = _postServices.GetFilteredPosts(forum, searchQuery).ToList(); var postListings = posts.Select(post => new PostListingModel { Id = post.Id, AuthorId = post.User.Id, AuthorName = post.User.UserName, AuthorRating = post.User.Rating, Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post) }); var model = new ForumTopicModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Topic(int id) { var forum = _forumService.GetById(id); var posts = forum.Posts; // ToDo : tu jest blad postListing jest nullem var postListings = posts.Select(post => new PostListingModel { Id = post.Id, AuthorId = post.User.Id, AuthorRating = post.User.Rating, Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post) }); var model = new ForumTopicModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Topic(int id) { var forum = _forumService.GetByID(id); //var posts = _postService.GetPostsByForum(id); REFACTORING var posts = forum.Posts; var postListings = posts.Select(p => new PostListingModel { Id = p.Id, AuthorId = p.User.Id, AuthorRating = p.User.Rating, Title = p.Title, DatePoster = p.Created, RepliesCount = p.Replies.Count(), Forum = BuildForumListing(p) }); var model = new ForumTopicModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
// 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)); }
public IActionResult Topics(int id) { var forum = _forumService.GetById(id); if (forum != null) { var topics = forum.Topics; var topicListings = topics.Select(topic => ModelBuilders.BuildTopicListing(topic)) .OrderByDescending(topic => topic.LastPostCreated); var model = new ForumTopicModel { Forum = ModelBuilders.BuildForumListing(forum), Topics = topicListings }; if (TempData["TopicDeletedMessage"] != null) { model.TopicDeletedMessage = TempData["TopicDeletedMessage"] as string; } return(View(model)); } return(RedirectToAction("Index", "Forum")); }
public IActionResult Topic(int id, string searchQuery) { var forum = _forumService.GetById(id); var posts = new List <Post>(); posts = _postService.GetFilteredPosts(forum, 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(), RepliesCount = post.Replies.Count() }).OrderByDescending(post => post.DatePosted); var model = new ForumTopicModel { //EmptySearchResults = noResults, Posts = postListings, //SearchQuery = searchQuery, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Topic(int forumId, string searchQuery) { var forum = _forumService.GetById(forumId); var posts = _postService.GetFilteredPosts(forum, searchQuery).ToList(); //Convert forum into list of posts. var postList = posts.Select(p => new ForumTopicListingModel { Id = p.Id, Title = p.Title, AuthorId = p.User.Id, AuthorName = p.User.UserName, AuthorRating = p.User.Rating, Created = p.Created.ToLocalTime().ToString("d"), RepliesCount = p.Replies.Count(), Forum = BuildForumListing(p) }); var model = new ForumTopicModel { Forum = BuildForumListing(forum), PostList = postList }; return(View(model)); }
public IActionResult Topic(int id, string searchQuery) { var forum = forumService.GetById(id); var posts = postService.GetFilteredPosts(forum, searchQuery).ToList(); var postListings = posts.Select(post => new PostListingModel { Id = post.Id, AuthorId = post.User.Id, AuthorName = post.User.UserName, AuthorImageUrl = post.User.ProfileImageUrl, AuthorRating = post.User.Rating, Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), LastReply = BuildPostReply(post.Replies.OrderByDescending(reply => reply.Created).FirstOrDefault()), Forum = BuildForumListing(post) }); var model = new ForumTopicModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Topic(int id, string searchQuery) { var forum = _forumService.GetById(id); var posts = new List <Post>(); posts = _postService.GetFIlteredPosts(forum, searchQuery).ToList(); var postListings = posts.Select(post => new PostListingModel { Id = post.Id, IdPembuat = post.User.Id, RatingPembuat = post.User.Rating, NamaPembuat = post.User.UserName, Judul = post.Judul, DatePosted = post.Dibuat.ToString(), JumlahBalasan = post.balasan.Count(), Forum = BuildForumListing(post) }); var model = new ForumTopicModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Topic(int id, string searchQuery) { var forum = _forumService.getById(id); var posts = _postService.getFilteredPosts(forum, searchQuery).ToList(); var postListings = posts.Select(post => new PostListingModel { id = post.id, authorId = post.user.Id, author = post.user.UserName, authorRating = post.user.rating, title = post.title, datePosted = post.created.ToString(), nrOfReplies = post.replies.Count(), forumListingModel = buildForumListing(post) }); var model = new ForumTopicModel { forum = buildForumList(forum), posts = postListings }; return(View(model)); }
public IActionResult Topic(int id) { var forum = _fourmSercice.GetById(id); var posts = forum.Posts; var PostListings = posts.Select(post => new PostListingModel { Id = post.Id, AuthorId = post.User.Id, AuthorName = post.User.UserName, AuthorRating = post.User.Rating, Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuilForunListing(post) }); var model = new ForumTopicModel { Posts = PostListings, Forum = BuilForunListing(forum) }; return(View(model)); }
public IActionResult Topic(int id) { var forum = _serviceForum.GetById(id); var posts = forum.Posts; var postListings = posts.Select(x => new PostListingModel { AuthorID = x.User.Id, Id = x.Id, AuthorRating = x.User.Rating, AuthorName = x.User.UserName, Title = x.Title, DatePosted = x.Created.ToString(), RepliesCount = x.PostReplies.Count(), Forum = BuildForumListing(x) }); var model = new ForumTopicModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
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 void Topic_WithSearchQuery_ReturnsFilteredPosts() { //Arrange var forumToReturn = new Forum(); var expectedPost = new Post() { Title = "Filtered Post", Forum = forumToReturn, User = new ApplicationUser(), Replies = new List <PostReply>() }; var listToReturn = new Post[] { expectedPost }; _postService.GetFilteredPosts(1, "query").Returns(listToReturn); _forumService.GetById(1).Returns(forumToReturn); //Act ViewResult view = (ViewResult)_controller.Topic(1, "query"); ForumTopicModel model = (ForumTopicModel)view.Model; var actualPost = model.Posts.First(); //Assert Assert.Equal(expectedPost.Title, actualPost.Title); }
public async Task <IActionResult> Topic(int id) { var forum = _forumService.GetById(id); var allPost = await _forumService.GetAllPostByForumId(id); //var postListings = allPost.Select(post => new PostListingModel //{ // Id = post.Id, // AuthorId = post.User.Id, // AuthorRating = post.User.Rating, // Title = post.Title, // DatePosted = post.Created.ToString(), // RepliesCount = post.Replies.Count(), // Forum = BuildForumListing(post) //}); var postListing = new List <PostListingModel>(); foreach (var post in allPost) { var postListModel = new PostListingModel { Id = post.PostId, AuthorId = post.Id, AuthorRating = post.ApplicationUsers.Rating, Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post) }; postListing.Add(postListModel); } var model = new ForumTopicModel { Posts = postListing, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Topic(int forumId, string searchQuery) { var forum = _forumService.GetById(forumId); var posts = _postService.GetSeacrhedPosts(forum, searchQuery); var forumViewModel = new ForumViewModel { Id = forum.Id, Description = forum.Description, Name = forum.Title, ImageUrl = forum.ImageUrl, UserName = forum.User.UserName, UserRating = forum.User.Rating, Created = forum.Created }; var postViewModels = posts.Select(p => new PostViewModel { Id = p.Id, AuthorId = p.User.Id, AuthorRating = p.User.Rating, AuthorName = p.User.UserName, Title = p.Title, DatePosted = p.Created.ToString("dd/MM/yyyy"), RepliesCount = p.Replies.Count(), }); var model = new ForumTopicModel { Posts = postViewModels, Forum = forumViewModel }; return(View(model)); }
public IActionResult Topic(int forumId, string searchQuery) { var forum = _forumService.GetById(forumId); var posts = _postService.GetSearchedPosts(forum, searchQuery); var postViewModels = posts.Select(post => new PostViewModel { Id = post.Id, AuthorId = post.User.Id, AuthorRating = post.User.Rating, AuthorName = post.User.UserName, Title = post.Title, DatePosted = post.Created.ToString("dd/MM/yyyy"), RepliesCount = post.Replies.Count(), Forum = ForumViewModelMapper(forum) }); var model = new ForumTopicModel { Posts = postViewModels, Forum = ForumViewModelMapper(forum) }; return(View(model)); }
public IActionResult Delete(int id) { var forum = _forumService.GetById(id); var posts = _postService.GetPostsByForum(id); 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, RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post) }); var model = new ForumTopicModel { Forum = BuildForumListing(forum), Posts = postListings }; return(View(model)); }
public IActionResult Topic(int id, string searchQuery) { var forum = _forumService.GetById(id); var posts = new List <Post>(); if (String.IsNullOrEmpty(searchQuery)) { posts = forum.Posts.ToList(); } else { posts = _postService.GetFilteredPosts(id, searchQuery).ToList(); } var postList = posts.Select(post => new PostListingModel { Id = post.Id, AuthorName = post.User.UserName, AuthorId = post.User.Id, AuthorRating = post.User.Rating, Title = post.Title, DatePosted = post.Created.ToString(), ReplyCount = post.Replies.Count(), Forum = BuildForumListing(post) }).ToList <PostListingModel>(); var model = new ForumTopicModel { Posts = postList, Forum = BuildForumListing(forum), SearchQuery = searchQuery }; return(View(model)); }
public async Task <IActionResult> Edit(ForumTopicModel model) { await _forumService.EditForum(model.Forum.Id, model.Forum.Name, model.Forum.Description); return(RedirectToAction("Topic", "Forum", new { id = model.Forum.Id })); }