Example #1
0
        public IPagedList <Video_vm> GetVideo_Vm(int?page)
        {
            int pageNumber = page ?? 1;
            int pageSize   = 5;
            var user       = UserAuthenticated.GetUser(User.Identity.Name);

            if (user != null)
            {
                var listWatched = _videoWatched.GetAll().Where(x => x.UserId == user.Id).OrderByDescending(x => x.Id).ToList();
                var video       = (from watched in listWatched
                                   join videos in _videoService.GetAll() on watched.VideoId equals videos.Id
                                   select videos).ToList();
                var listVideoVm = _videoService.GetVideo_Vm(video, _userService.GetAll()).ToPagedList(pageNumber, pageSize);
                return(listVideoVm);
            }
            return(null);
        }
        public IActionResult LibaryVideo()
        {
            ViewBag.ForCus = 3;
            var user = UserAuthenticated.GetUser(User.Identity.Name);

            ViewBag.UserFollow = _userService.GetUserFollow(user.UserName);
            ViewBag.IdUser     = user.Id;
            ViewBag.PlayList   = _playListService.GetAll().Where(x => x.UserId == ViewBag.IdUser).ToList();
            ViewBag.UserLibary = user;
            GetNotificationHome();
            if (user != null)
            {
                //Video watched
                var listVideoWatched = _videoWatched.GetAll().
                                       OrderByDescending(X => X.Id).Where(x => x.UserId == user.Id).ToList();

                var listvideo = (from video in _videoService.GetAll()
                                 join watched in listVideoWatched.Take(6).ToList() on video.Id equals watched.VideoId
                                 select video).ToList();
                var listvideo_vm = _videoService.GetVideo_Vm(listvideo, _userService.GetAll()).
                                   OrderByDescending(x => x.Id).ToPagedList(1, 6);
                ViewBag.CountWatched = listVideoWatched.Count;
                //-kết thúc
                //Video đã thích
                var listFovarited = _likeService.GeAll().Where(x => x.UserId == user.Id && x.Reaction == "Like").ToList();
                var listvideos    = (from fovarited in listFovarited
                                     join video in _videoService.GetAll() on fovarited.VideoId equals video.Id
                                     select video).ToList();
                var listVideoVm = _videoService.GetVideo_Vm(listvideos, _userService.GetAll());
                ViewBag.ListFovarited  = listVideoVm.ToPagedList(1, 3);
                ViewBag.CountFovarited = listFovarited.Count;
                //kết thúc
                ViewBag.CountUserFollow     = _followChannel.GetAll().Where(x => x.FromUserId == user.Id).Count();
                ViewBag.CountVideoUpload    = _videoService.GetAll().Where(x => x.AppUserId == user.Id).Count();
                ViewBag.CountDetailPlayList = _detailService.GetDetailPlayList(user, null).Count;
                ViewBag.DetailPlayList      = _detailService.GetDetailPlayList(user, null).ToPagedList(1, 4);
                return(View(listvideo_vm));
            }
            return(View(null));
        }