public IActionResult Index() { var forumsOld = _forumService.GetAllOldTestament().Select(forum => new ForumListingModel { Id = forum.Id, Title = forum.Title, Description = forum.Description, NumberOfPosts = forum.Posts?.Count() ?? 0, //check to see if its null < ? > NumberOfUsers = _forumService.GetActiveUsers(forum.Id).Count(), ImageUrl = forum.ImageUrl, HasRecentPost = _forumService.HasRecentPost(forum.Id), BookOrder = forum.BookOrder, OldOrNew = forum.OldOrNew }); var forumsNew = _forumService.GetAllNewTestament().Select(forum => new ForumListingModel { Id = forum.Id, Title = forum.Title, Description = forum.Description, NumberOfPosts = forum.Posts?.Count() ?? 0, //check to see if its null < ? > NumberOfUsers = _forumService.GetActiveUsers(forum.Id).Count(), ImageUrl = forum.ImageUrl, HasRecentPost = _forumService.HasRecentPost(forum.Id), BookOrder = forum.BookOrder, OldOrNew = forum.OldOrNew }); var model = new ForumIndexModel { ForumListingOld = forumsOld, ForumListingNew = forumsNew }; return(View(model)); }
// // GET: /Forum/ public ActionResult Index() { ForumIndexModel indexModel = new ForumIndexModel() { Forums = new Dictionary <string, Guid>() }; using (CGWebEntities entities = new CGWebEntities()) { if (Request.IsAuthenticated) { foreach (Forum forum in entities.Forums) { indexModel.Forums.Add(forum.ForumTitle, forum.ForumId); } } else { foreach (Forum forum in entities.Forums.Where(F => F.IsPublic)) { indexModel.Forums.Add(forum.ForumTitle, forum.ForumId); } } } return(View(indexModel)); }
// GET : Forum /// <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 "Forum". /// </summary> public IActionResult Index() { // FORCED casting like this does not work; it builds, but borks at runtime. //ForumListingModel forums = (ForumListingModel)_forumEntityService.GetAll() var forums = _forumEntityService.GetAll() .Select(forum => new ForumListingModel { Id = forum.Id, Title = forum.Title, ThreadCount = forum.Threads?.Count() ?? 0, UserCount = _forumEntityService.GetActiveUsers(forum.Id).Count(), HasRecentThread = _forumEntityService.HasRecentThread(forum.Id), //ImageUrl = forum.ImageUrl, Description = forum.Description }); var model = new ForumIndexModel { // NO FORCED CASTING ! //ForumList = (IEnumerable<ForumListingModel>)forums ForumList = forums.OrderBy(f => f.Title) }; return(View(model)); }
public IActionResult Index() { var forums = _forumService.GetAll().Select(f => new ForumListingModel { Id = f.Id, Name = f.Title, Description = f.Description, NumberOfPosts = f.Posts?.Count() ?? 0, //Latest = GetLatestPost(f.Id) ?? new PostListingModel(), NumberOfUsers = _forumService.GetActiveUsers(f.Id).Count(), ImageUrl = f.ImageUrl, HasRecentPost = _forumService.HasRecentPost(f.Id) }); //var forumListingModels = forums as IList<ForumListingModel> ?? forums.ToList(); var model = new ForumIndexModel { ForumList = forums.OrderByDescending(f => f.Id) //ForumList = forumListingModels.OrderBy(forum => forum.Name), //NumberOfForums = forumListingModels.Count() }; return(View(model)); }
public IActionResult Index() { var forums = _mapper.Map <List <ForumListingModel> >(_forumService .GetAll()); var model = new ForumIndexModel(forums); return(View(model)); }
public IActionResult Index() { var forums = _forum.GetAll(); var model = new ForumIndexModel { ForumsList = forums }; return(View(model)); }
//Home Forum News public IActionResult Index() { var forumGroups = _forumService.GetAll().GroupBy(f => f.Id); List <ForumViewModel> forumList = new List <ForumViewModel>(); List <PostViewModel> postsForum = new List <PostViewModel>(); foreach (var forumGroup in forumGroups) { postsForum = new List <PostViewModel>(); //Lặp qua tất cả các bài post rồi add vào IEnum ForumList foreach (var post in forumGroup.FirstOrDefault().Posts) { postsForum.Add(new PostViewModel { Id = post.Id, Title = post.Title, Content = post.Content, Created = post.Created, NumberRead = post.NumberRead, Status = post.Status, }); } //Nhận cái bài post sau khi lặp ở trên forumList.Add(new ForumViewModel { Id = forumGroup.FirstOrDefault().Id, Description = forumGroup.FirstOrDefault().Description, ImageUrl = forumGroup.FirstOrDefault().ImageUrl, Title = forumGroup.FirstOrDefault().Title, //Chứa toàn bộ bài viết theo chủ đề PostsForum = postsForum.OrderByDescending(post => post.Created).Where(p => p.Status == true).Take(5) }); } var nPost = _postService.GetLastesPost(5); var postNews = nPost.Select(p => new PostViewModel { Id = p.Id, Title = p.Title, Content = p.Content, Created = p.Created, AuthorName = p.User.UserName }); var model = new ForumIndexModel { ForumList = forumList, NewsPostList = postNews }; return(View(model)); }
public IActionResult Index() { var forums = _forumService.GetAll().Select(f => ForumViewModelMapper(f)); var model = new ForumIndexModel { ForumList = forums }; return(View(model)); }
public IActionResult Index() { var forums = _fourmSercice.GetAll().Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Description = forum.Description }); var model = new ForumIndexModel { ForumList = forums }; return(View(model)); }
public IActionResult Index() { var forums = _forumService.getAll().Select(forum => new ForumListingModel { id = forum.id, name = forum.title, description = forum.description }); var model = new ForumIndexModel { forumList = forums }; return(View(model)); }
public IActionResult Index() { IEnumerable <ForumListingModel> forums = _forumService.GetAll() .Select(forum => new ForumListingModel() { Id = forum.Id, Name = forum.Title, Description = forum.Description }); var model = new ForumIndexModel() { ForumList = forums }; return(View(model)); }
public IActionResult Index() { var forums = _serviceForum.GetAll().Select(x => new ForumListingModel { Id = x.Id, Name = x.Title, Description = x.Description }); var model = new ForumIndexModel { ForumList = forums }; return(View(model)); }
public IActionResult Index() { var forums = _forumService.GetAll().Select(forum => ModelBuilders.BuildForumListing(forum)); var model = new ForumIndexModel { ForumList = forums }; if (TempData["ForumDeletedMessage"] != null) { model.ForumDeletedMessage = TempData["ForumDeletedMessage"] as string; } return(View(model)); }
public IActionResult Index() { var forums = _forumService.GetAll() .Select(forum => new ForumListingModel { Id = forum.Id, Title = forum.Name, Description = forum.Description, Created = forum.Created }); var forumModel = new ForumIndexModel { ForumList = forums }; return(View(forumModel)); }
public IActionResult Index() { var forums = _forumService.GetAll() .Select(f => new ForumListingModel { Id = f.Id, Title = f.Title, Description = f.Description } ).OrderBy(f => f.Title); var model = new ForumIndexModel { ForumList = forums }; return(View(model)); }
public IActionResult Index() { var forums = _forumService.GetAll().Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Description = forum.Description, NumberOfPosts = forum.Posts?.Count() ?? 0, NumberOfUsers = _forumService.GetActiveUsers(forum.Id).Count(), ImageUrl = forum.UrlImage, HasRecentPost = _forumService.HasRecentPost(forum.Id) }); var model = new ForumIndexModel { ForumList = forums.OrderBy(f => f.Name) }; return(View(model)); }
public IActionResult Index() { /*var type is IEnumerable<ForumListingModel>*/ var forums = _forumService.GetAll() .Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Description = forum.Description }); //Mapping each forum from database to a ForumListingModel Object var model = new ForumIndexModel { ForumList = forums }; //assigning the collection of the ForumListingModels to the ForumList member of the ForumIndexModel object return(View(model)); }
public void Index_GivenForums_ReturnsTheForums(int expectedAmount) { //Arrange List <Forum> forumsToReturn = new List <Forum>(); for (int i = 0; i < expectedAmount; i++) { forumsToReturn.Add(new Forum()); } _forumService.GetAll().Returns(forumsToReturn); //Act ViewResult view = (ViewResult)_controller.Index(); ForumIndexModel model = (ForumIndexModel)view.Model; //Assert Assert.Equal(expectedAmount, model.ForumList.Count()); }
public async Task <IActionResult> Index() { IEnumerable <Forum> forums = await _forumService.GetAllAsync(); var forumsListings = forums.Select(x => new ForumListingData { Id = x.Id, Name = x.Title, Description = x.Description }); var vm = new ForumIndexModel { ForumList = forumsListings, }; return(View(vm)); }
public IActionResult Index() { var latestPosts = _postService.GetLatestPosts(5); var latestForums = _forumService.GetLatestForums(5); var latestForumsMapped = latestForums.Select(f => new ForumViewModel { Id = f.Id, Description = f.Description, ImageUrl = f.ImageUrl, Name = f.Title, UserId = f.User.Id, UserName = f.User.UserName, UserRating = f.User.Rating, Created = f.Created, PostsCount = f.Posts.Count() }); var latestPostsMaped = latestPosts.Select(p => new PostViewModel { Id = p.Id, Title = p.Title, AuthorId = p.User.Id, AuthorName = p.User.UserName, AuthorRating = p.User.Rating, DatePosted = p.Created.ToString(), RepliesCount = p.Replies.Count(), Forum = new ForumViewModel { Id = p.Forum.Id, Name = p.Forum.Title, ImageUrl = p.Forum.ImageUrl } }); var model = new ForumIndexModel() { LatestPosts = latestPostsMaped, ForumViewModels = latestForumsMapped }; return(View(model)); }
public IActionResult Index() { // Get all forums // map properties of the FOrum object into instances of the FormViewModel var forums = _forumService.GetAll() .Select(forum => new ForumListingViewModel { Id = forum.Id, Name = forum.Title, Description = forum.Description }); var model = new ForumIndexModel { ForumListing = forums }; return(View(forums)); }
public IActionResult Topic(string searchQuery) { var forums = new List <Forum>(); forums = _forumService.GetFilteredForums(searchQuery).ToList(); var forumListing = forums.Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Value = forum.Value, ImgUrl = forum.ImageUrl }); var model = new ForumIndexModel { ForumList = forumListing }; return(View(model)); }
public IActionResult Index() { //forum -- коллекция объектов ForumListingModel (var = IEnumerable<ForumListingModel>) //и возвращаться должен тот самый объект (new ForumListingModel) var forums = _forumService .GetAll() .Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Description = forum.Description }); var model = new ForumIndexModel { ForumList = forums }; return(View(model)); }
public IActionResult Index() { IEnumerable <ForumListingModel> forums = _forumService.GetAll() .Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Description = forum.Description, NumberOfPosts = forum.Posts?.Count() ?? 0, Latest = GetLatestPost(forum.Id) ?? new PostListingModel(), NumberOfUsers = _forumService.GetActiveUsers(forum.Id).Count(), ImageUrl = forum.ImageUrl, HasRecentPost = _forumService.HasRecentPost(forum.Id) }); var model = new ForumIndexModel { ForumList = forums }; return(View(model)); }
public IActionResult Index() { var forums = _forumService.GetAll() .Select(forum => new ForumListingModel { Id = forum.Id, Nama = forum.Judul, Deskripsi = forum.Deskripsi, nomorPost = forum.Posts?.Count() ?? 0, nomorUser = _forumService.GetActiveUsers(forum.Id).Count(), ImageUrl = forum.ImageUrl, postBaru = _forumService.postBaru(forum.Id) }); var model = new ForumIndexModel { ForumList = forums.OrderBy(f => f.Nama) }; return(View(model)); }
public IActionResult Index() { var forums = _forumService.GetAll() //var is IEnumerable<ForumListingModel> .Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Description = forum.Description, NumberOfPosts = forum.Posts?.Count() ?? 0, NumberOfUsers = _forumService.GetActiveUsers(forum.Id).Count(), ImageUrl = forum.ImageUrl, HasRecentPost = _forumService.HasRecentPost(forum.Id) }); var model = new ForumIndexModel { ForumList = forums.OrderBy(f => f.Name) }; return(View(model)); //here we can return a view of name of our controller or status code or some JSON data }
public IActionResult Index() { var forums = _forumService.GetAll() .Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Description = forum.Description, //if form.Posts is not null, take that as a value(including .Count) //if it's null, take 0 as value NumberOfPosts = forum.Posts?.Count() ?? 0, NumberOfUsers = _forumService.GetActiveUsers(forum.Id).Count(), ImageUrl = forum.ImageUrl, HasRecentPost = _forumService.HasRecentPost(forum.Id) }); var model = new ForumIndexModel { ForumList = forums.OrderBy(f => f.Name) }; return(View(model)); }
public IActionResult Index() { var forums = _forumService.GetAll() .Select(forum => new ForumViewModel { Id = forum.Id, Name = forum.Title, Description = forum.Description, PostsCount = forum.Posts.Count(), UserName = forum.User.UserName, UserRating = forum.User.Rating, Created = forum.Created }); var model = new ForumIndexModel { ForumViewModels = forums }; return(View(model)); }
//Forum object is EntityModel - maps c# object back to //the represtatio of this data in the data store. //Don't pass the raw entity model to the view, pass a viewModel instead. //Index page doen't need a full form object, create a simplified view model to pass down public IActionResult Index() { //Forums retrieves all objects from the database using GetAll() //Select uses Linq to map the properties on each Forum object into //instances of the new forum listing model IEnumerable <ForumListingModel> forums = _forumService.GetAll() //From the service layer .Select(forum => new ForumListingModel { Id = forum.Id, Name = forum.Title, Description = forum.Description }); //Creates a collection of Forums var model = new ForumIndexModel { ForumList = forums //Populated from the above service layer }; //The entrie wrapped forum index model is passed to the view, //and accessed in the Views/Forum/Index.cshtml by the first line in razor //MVC will look for a View called Index, in a folder called Forum return(View(model)); }