Exemple #1
0
        public IActionResult Index(string category, int forumPage = 1)
        {
            var forums = _forumService.GetAll()
                         .Select(forum => new ForumListingModel
            {
                Id     = forum.Id,
                Name   = forum.Title,
                Value  = forum.Value,
                ImgUrl = forum.ImageUrl
            });
            var model = new ForumSearchQuery
            {
                Forum = forums
                        .Where(p => p.Name == category || category == null)
                        .OrderBy(p => p.Id)
                        .Skip((forumPage - 1) * PageSize)
                        .Take(PageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = forumPage,
                    ItemsPerPage = PageSize,
                    TotalItems   = category == null?
                                   forums.Count() :
                                       forums.Where(e => e.Name == category).Count()
                                       //TotalItems = forums.Count()
                },
                CurrentCategory = category
            };

            return(View(model));
        }
Exemple #2
0
        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));
        }
Exemple #4
0
        public IActionResult Index()
        {
            var forums = _forum.GetAll();
            var model  = new ForumIndexModel
            {
                ForumsList = forums
            };

            return(View(model));
        }
Exemple #5
0
        public IActionResult Index()
        {
            var forums = _forumService.GetAll().Select(f => ForumViewModelMapper(f));


            var model = new ForumIndexModel
            {
                ForumList = 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));
        }
Exemple #7
0
        public IActionResult Index()
        {
            var forums = _forumService.GetAll()
                         .Select(forum => new ForumListingModel
            {
                Id            = forum.Id,
                Name          = forum.Title,
                Description   = forum.Description,
                ImageUrl      = forum.ImageUrl,
                NumberOfPosts = forum.Posts?.Count() ?? 0,
                NumberOfUsers = _forumService.GetActiveUsers(forum.Id).Count(),
                HasRecentPost = _forumService.HasRecentPost(forum.Id)
            });

            var model = new ForumIndexModel
            {
                ForumList = forums.OrderBy(f => f.Name)
            };

            return(View(model));
        }
Exemple #8
0
        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));
        }
Exemple #9
0
        public IViewComponentResult Invoke()
        {
            var forums = _forumService.GetAll()
                         .Select(forum => new ForumListingModel
            {
                Id   = forum.Id,
                Name = forum.Title,
            });

            ViewBag.SelectedCategory = RouteData?.Values["category"];
            return(View(forums
                        .Select(x => x.Name)
                        .Distinct()
                        .OrderBy(x => x)));
        }
        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));
        }
Exemple #11
0
        public IActionResult Index()
        {
            var numberUsers   = _userManager.Users.Count();
            var numberPosts   = _postService.GetAll().Where(post => post.Status == false).Count();
            var numberReplies = _commentService.GetAll().Count();
            var numberForum   = _forumService.GetAll().Count();
            var model         = new HomeViewModel
            {
                CountUsers   = numberUsers,
                CountPosts   = numberPosts,
                CountReplies = numberReplies,
                CountForums  = numberForum
            };

            return(View(model));
        }
Exemple #12
0
        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));
        }
Exemple #13
0
        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));
        }
Exemple #14
0
        private HomeIndexModel HomeIndexModel()
        {
            var latestPosts  = _post.GetLatestPosts(10);
            var popularPosts = _post.GetMostPopularPosts(10);
            var forumvar     = _forum.GetAll();

            var forums = forumvar.Select(f => new ForumListingModel
            {
                Id            = f.Id,
                Title         = f.Title,
                Description   = f.Description,
                NumberOfPosts = f.Posts?.Count() ?? 0,
                NumberOfUsers = _forum.GetAllActiveUsers(f.Id).Count(),
                ForumImageUrl = f.ImageUrl,
                HasRecentPost = _forum.HasRecentPost(f.Id)
            });

            var posts = latestPosts.Select(p => new PostListingModel {
                Id           = p.Id,
                Title        = p.Title,
                AuthorName   = p.User.UserName,
                AuthorId     = p.User.Id.ToString(),
                AuthorRating = p.User.Rating,
                DatePosted   = p.Created.ToString(),
                RepliesCount = p.Replies.Count(),
                Forum        = GetForumListingForPost(p)
            });
            var postsPopular = popularPosts.Select(p => new PostListingModel {
                Id           = p.Id,
                Title        = p.Title,
                AuthorName   = p.User.UserName,
                AuthorId     = p.User.Id.ToString(),
                AuthorRating = p.User.Rating,
                DatePosted   = p.Created.ToString(),
                RepliesCount = p.Replies.Count(),
                Forum        = GetForumListingForPost(p)
            });

            return(new HomeIndexModel
            {
                LatestPosts = posts,
                PopularPosts = postsPopular,
                SearchQuery = "",
                Forums = forums
            });
        }
Exemple #15
0
        public IActionResult Index()
        {
            IEnumerable <ForumVM> forums = _forumService.GetAll()
                                           .Select(forum => new ForumVM
            {
                Id          = forum.Id,
                Title       = forum.Title,
                Description = forum.Description,
                PostsCount  = forum.Posts.Count()
            });
            var vm = new ForumIndexVM()
            {
                ForumList = forums
            };

            return(View(vm));
        }
Exemple #16
0
        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));
        }
Exemple #17
0
        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());
        }
Exemple #18
0
        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 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));
        }
Exemple #20
0
        /*public ForumController()
         * {
         *  this._forumRepositories = _forumRepositories;
         * }*/
        // GET: Forum
        public ActionResult Index()
        {
            var forums = _forumRepositories.GetAll().Select(forum => new ForumListingModel
            {
                Id          = forum.Id,
                Name        = forum.Title,
                Description = forum.Description,
                Created     = forum.Created.ToString(),
                postsCount  = forum.Posts.Count,
                ActiveUsers = _forumRepositories.GetAllActiveUsers(forum.Id).Count()
            });

            var model = new ForumIndexViewModel
            {
                ForumList = forums
            };

            return(View(model));
        }
Exemple #21
0
        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));
        }
Exemple #22
0
        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
        }
Exemple #23
0
        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));
        }
Exemple #24
0
        public IActionResult Index()
        {
            var forumsList = forumService.GetAll()
                             .Select(forum => new ForumListingViewModel
            {
                Id            = forum.Id,
                Title         = 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 viewModel = new ForumIndexViewModel()
            {
                ForumList = forumsList.OrderBy(f => f.Title)
            };

            return(View(viewModel));
        }
        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));
        }
Exemple #26
0
        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));
        }
        public IActionResult Index()
        {
            var forums = _forumService.GetAll().Select(f => new ForumListingVM
            {
                Id            = f.Id,
                Title         = f.Title,
                Description   = f.Description,
                NumberOfPosts = f.Posts?.Count() ?? 0,
                Latest        = GetLatestPost(f.Id) ?? new PostListingVM(),
                NumberOfUsers = _forumService.GetActiveUsers(f.Id).Count(),
                Image         = f.Image,
                HasRecentPost = _forumService.HasRecentPost(f.Id)
            });

            var forumsListingModels = forums as IList <ForumListingVM> ?? forums.ToList();

            var model = new ForumIndexVM
            {
                ForumsList     = forumsListingModels.OrderBy(forum => forum.Title),
                NumberOfForums = forumsListingModels.Count()
            };

            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));
        }
Exemple #29
0
        public static IEnumerable <ForumInfo> GetAllForums()
        {
            IForum dal = Factory <IForum> .Create("Forum");

            return(dal.GetAll());
        }
Exemple #30
0
 public IEnumerable <Forum> GetAll()
 {
     return(_context.GetAll());
 }