public IActionResult MyChannel_Partial(int?page) { if (page == null) { page = 1; } var pageSize = 6; var pageNumber = page ?? 1; var user = _userService.FindUser(User.Identity.Name).Result; var list = _videoService.GetAll(). Where(x => x.AppUserId == user.Id).OrderByDescending(x => x.Id).ToPagedList(pageNumber, pageSize); var listCountComment = (from video in _videoService.GetAll().Where(x => x.AppUserId == user.Id) join comment in _commentService.GetAll() on video.Id equals comment.VideoId orderby video.Id, comment.Id descending group comment by comment.VideoId into grp select new { Key = grp.Key, Count = grp.Count() }).ToList(); var listCount = new List <CountComment>(); foreach (var item in listCountComment) { var count = new CountComment(); count.Id = item.Key; count.Count = item.Count; listCount.Add(count); } ViewBag.CountComment = listCount; return(View(list)); }
public List <CountComment> GetCountCm() { var listCount = new List <CountComment>(); var listCountComment = (from vd in _context.Video.ToList() join cm in GetAll() on vd.Id equals cm.VideoId group cm by cm.VideoId into grp select new { grp.Key, Count = grp.Count() }).OrderByDescending(x => x.Key).ToList(); foreach (var item in listCountComment) { var i = new CountComment(); i.Id = item.Key; i.Count = item.Count; listCount.Add(i); } return(listCount); }