public async Task <IActionResult> Create(string likeDetail) { var like = JsonConvert.DeserializeObject <LikeVideoRequest>(likeDetail); int result = 0; if (like.Reaction == Reactions.DontLike.ToString() || like.Reaction == Reactions.DontDisLike.ToString()) { var getLike = await _likeService.FindAsync(like.UserId, like.VideoId); result = await _likeService.Delete(getLike.Id); } else { result = await _likeService.Create(like); } if (result > 0) { var resultUpdate = await _videoService.UpdateLike(like.VideoId, like.Reaction); if (resultUpdate > 0) { int getLike = 0; var getVideo = await _videoService.FinVideoAsync(like.VideoId); if (like.Reaction == "Like" || like.Reaction == Reactions.DontLike.ToString()) { getLike = getVideo.Like; } if (like.Reaction == "DisLike" || like.Reaction == Reactions.DontDisLike.ToString()) { getLike = getVideo.DisLike; } return(Content(getLike.ToString())); } } return(Content("Error")); }
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)); }