public async Task <IActionResult> Create(Guid?forumId, ForumTopicViewModel model) { if (forumId == null) { return(this.NotFound()); } var user = await this.userManager.GetUserAsync(this.HttpContext.User); if (this.ModelState.IsValid && user != null) { var forumTopic = new ForumTopic { Created = DateTime.UtcNow, Name = model.Name, ForumId = (Guid)forumId, UserId = user.Id }; this.context.ForumTopics.Add(forumTopic); await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index", new { forumId })); } return(this.View(model)); }
protected override void Init(Bundle savedInstanceState) { ViewModel = ViewModelLocator.ForumsTopic; ViewModel.RequestScroll += ViewModelOnRequestScroll; ViewModel.ScrollInfoProvider = this; ViewModel.Init(_args); }
// GET: ForumTopics/Edit/5 public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(this.NotFound()); } var forumTopic = await this.context.ForumTopics.SingleOrDefaultAsync(m => m.Id == id); if (forumTopic == null) { return(this.NotFound()); } var model = new ForumTopicViewModel { Name = forumTopic.Name }; var forumCategories = await this.context.ForumCategories.OrderBy(x => x.Name).ToListAsync(); this.ViewBag.ForumId = forumTopic.ForumId; this.ViewBag.UserId = forumTopic.UserId; return(this.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 PostListingViewModel() { Id = post.Id, AuthorId = post.User.Id, AuthorRating = post.User.Rating, AuthorName = post.User.Nickname, Title = post.Title, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), Forum = BuildForumListing(post) }); var model = new ForumTopicViewModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
public async Task <IActionResult> Edit(Guid?id, Guid?forumId, ForumTopicViewModel model) { if (id == null || forumId == null) { return(this.NotFound()); } var forumTopic = await this.context.ForumTopics.SingleOrDefaultAsync(m => m.Id == id); if (forumTopic == null) { return(this.NotFound()); } if (this.ModelState.IsValid) { forumTopic.Name = model.Name; await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index", new { forumId })); } return(this.View(model)); }
public IActionResult Topic(int id, string searchQuery)/*FIX THE CODE ERROR BELOW!*/ { var forum = _forumService.GetById(id); var posts = new List <Post>(); posts = _postService.GetFilteredPosts(forum, searchQuery).ToList(); //forum.Posts; var postListings = posts.Select(post => new PostListViewModel { Id = post.Id, AuthorId = post.User.Id, AuthorRating = post.User.Rating, AuthorName = post.User.UserName, //Fix the naming Title = post.Title, DatePosted = post.DateCreated.ToString(), ReplyAmount = post.Replies.Count(), Forum = _forumBLL.BuildForumListing(post) }); var model = new ForumTopicViewModel { Posts = postListings, Forum = _forumBLL.BuildForumListing(forum) }; return(View(model)); //THIS CODE GIVES NULL ERROR //var topic = _forumBLL.GetTopic(id,searchQuery); //return View(topic); }
public ForumTopicViewModel GetTopic(int id, string searchQuery) { var forum = _forumService.GetById(id); var posts = new List <Post>(); posts = _postService.GetFilteredPosts(forum, searchQuery).ToList(); //forum.Posts; var postListings = posts.Select(post => new PostListViewModel { Id = post.Id, AuthorId = post.User.Id, AuthorRating = post.User.Rating, AuthorName = post.User.UserName, //Fix the naming Title = post.Title, DatePosted = post.DateCreated.ToString(), ReplyAmount = post.Replies.Count(), Forum = BuildForumListing(post) }); var model = new ForumTopicViewModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(model); }
public ActionResult Topic(int id, string searchQuery) { var forum = _forumRepositories.GetById(id); var posts = new List <Post>(); posts = _postRepositories.GetFilteredPosts(forum, searchQuery).ToList(); var postListing = posts.Select(post => new PostListingModel { Id = post.Id, Title = post.Title, AuthorName = post.User.UserName, AuthorId = post.User.Id, DatePosted = post.Created.ToString(), RepliesCount = post.Replies.Count(), AuthorRating = post.User.Rating, Forum = BuildForumListing(post) }); var model = new ForumTopicViewModel { Posts = postListing, Forum = BuildForumListing(forum) }; return(View(model)); }
public IActionResult Topic(int id) { var helper = new Helpers.ForumHelper(); var forum = _forumService.GetById(id); var posts = forum.Posts; var postListings = posts.Select(p => new PostListingViewModel { Id = p.Id, AuthorId = Convert.ToInt32(p.User.Id), AuthorName = p.User.UserName, AuthorRating = p.User.Rating, Title = p.Title, DatePosted = p.Created.ToString("MMM dd yyyy"), RepliesCount = p.Replies.Count(), Forums = helper.BuildForumListing(forum) }); var vm = new ForumTopicViewModel { Posts = postListings, Forum = helper.BuildForumListing(forum) }; return(View(vm)); }
public IActionResult Topic(int id, string searchQuery) { var forum = this.forumsService.GetById(id); var posts = this.forumsService.GetFilteredPosts(id, searchQuery).ToList(); var noResults = !string.IsNullOrEmpty(searchQuery) && !posts.Any(); ForumTopicViewModel model; if (forum.Posts.Any()) { var postsListing = posts.Select(post => new PostListingViewModel { Id = post.Id, AuthorId = post.User.Id, AuthorName = post.User.UserName, AuthorRating = post.User.Rating,// == null ? 0 : post.User.Rating, Title = post.Title, DatePosted = post.CreatedOn.ToString(CultureInfo.InvariantCulture), RepliesCount = post.Replies.Count(),// == null ? 0 : post.Replies.Count(), Forum = this.BuildForumListing(post), }).OrderByDescending(post => post.DatePosted) .ToList(); model = new ForumTopicViewModel { Posts = postsListing, Forum = this.BuildForumListing(forum), SearchQuery = searchQuery, EmptySearchResults = noResults, }; return(this.View(model)); } model = new ForumTopicViewModel { Posts = new List <PostListingViewModel>(), Forum = this.BuildForumListing(forum), SearchQuery = searchQuery, EmptySearchResults = noResults, }; return(this.View(model)); }
public IActionResult Topic(int id) { var forum = _forumService.GetById(id); var posts = forum.Posts; var postListings = posts.Select(x => new PostListingModel { Id = x.Id, AuthorId = x.User.Id, AuthorRating = x.User.Rating, Title = x.Title, DatePosted = x.Created.ToString(), RepliesCount = x.Replies.Count(), Forum = BuildForumListing(x) }); var model = new ForumTopicViewModel { Posts = postListings, Forum = BuildForumListing(forum) }; return(View(model)); }
public void Include(ForumTopicViewModel vm) { var vm1 = new ForumTopicViewModel(null); }
protected override void Init(Bundle savedInstanceState) { ViewModel = ViewModelLocator.ForumsTopic; ViewModel.Init(_args); }