public ActionResult MyPage(int?page, int?idUser)
        {
            GetNotificationHome();

            var             pageNumber = page ?? 1;
            List <Video_vm> listVideo_Vm;
            var             listVideo = new List <Video>();
            var             users     = UserAuthenticated.GetUser(User.Identity.Name);

            if (users != null)
            {
                ViewBag.IdUser     = users.Id;
                ViewBag.UserFollow = _userService.GetUserFollow(users.UserName);
                ViewBag.PlayList   = _playListService.GetAll().Where(x => x.UserId == users.Id).ToList();
            }
            else
            {
                ViewBag.PlayList   = null;
                ViewBag.UserFollow = _userService.GetChannel();
            }

            if (idUser != null)
            {
                var user = _userService.FindUserId((int)idUser).Result;
                ViewBag.CountUserFollow = _followChannel.GetAll().Where(x => x.ToUserId == user.Id).Count();
                ViewBag.UserMyPage      = user;
                listVideo = _videoService.GetAll().Where(x => x.AppUserId == idUser).ToList();
            }
            else
            {
                if (page == null)
                {
                    page = 1;
                }
                ViewBag.CountUserFollow = _followChannel.GetAll().Where(x => x.ToUserId == users.Id).Count();
                ViewBag.UserMyPage      = users;
                listVideo = _videoService.GetAll().Where(x => x.AppUserId == users.Id).ToList();
            }
            if (users == null || idUser != users.Id && idUser != null)
            {
                ViewBag.FollowUser = true;
            }
            else
            {
                ViewBag.FollowUser = false;
            }
            ViewBag.BottomPage = true;
            var listUser = _userService.GetAll();

            listVideo_Vm = _videoService.GetVideo_Vm(listVideo, listUser).
                           OrderByDescending(x => x.Id).Where(x => x.Status & x.HidenVideo).ToList();
            return(View(listVideo_Vm.ToPagedList(pageNumber, 8)));
        }
Exemplo n.º 2
0
        public IActionResult AnalysisUser(int id)
        {
            ViewBag.IdUser           = id;
            ViewBag.UserFollow       = _followChanel.GetAll().Where(x => x.ToUserId == id).Count();
            ViewBag.CountViewChannel = _videoService.GetAll().Where(x => x.AppUserId == id).Sum(x => x.ViewCount);
            ViewBag.CountVideo       = _videoService.GetAll().Where(x => x.AppUserId == id).Count();
            ViewBag.CountReport      = (from report in _reportService.GetAll()
                                        join video in _videoService.GetAll().Where(x => x.AppUserId == id) on report.VideoId equals video.Id
                                        select report).Count();
            ViewBag.CoutCategory = _videoService.GetAll().Where(x => x.AppUserId == id).GroupBy(x => x.CategorysId).Count();
            var listRankedVideo = _videoService.GetAll().Where(x => x.AppUserId == id).OrderByDescending(x => x.ViewCount).Take(10).ToList();

            return(View(listRankedVideo));
        }
        public IActionResult SubscriptionChannel(int?page, bool flag = false)
        {
            ViewBag.ForCus = 2;
            GetNotificationHome();
            if (page == null)
            {
                page = 1;
            }
            var pageNumber = page ?? 1;
            var pageSize   = 12;
            IPagedList <Video_vm> listVideo_Vm;

            if (User.Identity.IsAuthenticated)
            {
                var userLogin = UserAuthenticated.GetUser(User.Identity.Name);
                ViewBag.UserFollow = _userService.GetUserFollow(userLogin.UserName);
                ViewBag.IdUser     = userLogin.Id;
                ViewBag.PlayList   = _playListService.GetAll().Where(x => x.UserId == ViewBag.IdUser).ToList();
                var listFollow = _channelService.GetAll().Where(x => x.FromUserId == userLogin.Id).ToList();
                var listVideo  = (from video in _videoService.GetAll()
                                  join follow in listFollow on video.AppUserId equals follow.ToUserId
                                  select video).ToList();
                var listUser = _userService.GetAll();
                listVideo_Vm = _videoService.GetVideo_Vm(listVideo, listUser).
                               OrderByDescending(x => x.Id).ToPagedList(pageNumber, pageSize);
                if (flag)
                {
                    foreach (var item in listVideo_Vm)
                    {
                        item.CreateDate = CaculatorHours.Caculator(item.CreateDate);
                    }
                    return(Content(JsonConvert.SerializeObject(listVideo_Vm)));
                }
                return(View(listVideo_Vm));
            }
            listVideo_Vm = null;
            return(View(listVideo_Vm));
        }
        public async Task <IActionResult> DetailVideo(int?id)
        {
            GetNotificationHome();
            var userFollow = "false";
            var userLogin  = UserAuthenticated.GetUser(User.Identity.Name);

            if (userLogin != null)
            {
                ViewBag.UserFollow = _userService.GetUserFollow(userLogin.UserName);
                ViewBag.IdUser     = userLogin.Id;
                ViewBag.PlayList   = _playListService.GetAll().Where(x => x.UserId == ViewBag.IdUser).ToList();
            }
            else
            {
                ViewBag.UserFollow = _userService.GetChannel();
                ViewBag.PlayList   = null;
            }
            ViewBag.UserLogin = userLogin == null ? null : userLogin;
            var userIdLogin = userLogin == null ? 0 : userLogin.Id;
            var video       = await _videoService.FinVideoAsync((int)id);

            var video_Vm = new Video_vm();

            if (video != null)
            {
                var user = await _userManager.FindByIdAsync(video.AppUserId.ToString());

                var like = await _likeVideo.FindAsync(userIdLogin, video.Id);

                video_Vm.PosterImg     = video.PosterImg;
                video_Vm.Name          = video.Name;
                video_Vm.Id            = video.Id;
                video_Vm.Reaction      = like == null ? " " : like.Reaction;
                video_Vm.LinkVideo     = video.LinkVideo;
                video_Vm.Avartar       = user.Avartar;
                video_Vm.FirtsName     = user.FirtsName;
                video_Vm.Like          = video.Like;
                video_Vm.UserLike      = like == null ? 0 : like.UserId;
                video_Vm.DisLike       = video.DisLike;
                video_Vm.LastName      = user.LastName;
                video_Vm.ViewCount     = video.ViewCount;
                video_Vm.AppUserId     = video.AppUserId;
                video_Vm.Description   = video.Description;
                video_Vm.LoginExternal = user.LoginExternal;
                video_Vm.CreateDate    = video.CreateDate;
                var lVideo = _videoService.GetAll().Where(x => x.CategorysId == video.CategorysId && x.Id != video.Id && x.HidenVideo).ToList();
                var lUser  = _userService.GetAll();
                if (userLogin != null)
                {
                    if (CheckUserFollow(userLogin.Id, video_Vm.AppUserId))
                    {
                        userFollow = "true";
                    }
                }
                var comment = _commentService.GetAll().Where(x => x.VideoId == video.Id).ToList();
                ViewBag.VideoRelationShip = _videoService.GetVideo_Vm(lVideo, lUser).OrderByDescending(x => x.Id).ToPagedList(1, 8).ToList();
                ViewBag.Comment           = _commentService.GetAll_vm(lUser, comment).OrderByDescending(x => x.Id).ToList();
                ViewBag.CheckUserFollow   = userFollow;
                ViewBag.CountRegister     = _channelService.GetAll().Where(x => x.ToUserId == video_Vm.AppUserId).Count();
            }
            return(View(video_Vm));
        }