示例#1
0
        public IActionResult DislikeVideo(long id)
        {
            var loggedInUserId = HttpContext.Session.GetString("LoggedInUserId");

            if (loggedInUserId == null)
            {
                return(StatusCode(401));
            }
            User user = _userData.GetById(long.Parse(loggedInUserId));

            if (user == null)
            {
                return(StatusCode(401));
            }
            Video video = _videoData.GetById(id);

            if (_likeDislikeData.Check(false, user.Id, video.Id))
            {
                return(Json("Already liked"));
            }
            LikeDislikeVideo ld = new LikeDislikeVideo();

            ld.LikeOrDislike = false;
            ld.Owner         = user;
            ld.Video         = video;
            ld.CreationDate  = DateTime.Today;
            _likeDislikeData.Add(ld);
            video.NumberOfDislikes++;
            _videoData.Update(video);
            return(Json("Success"));
        }
示例#2
0
        public bool Check(bool likeDislike, long userId, long videoId)
        {
            LikeDislikeVideo exist = _context.LikeDislikeVideos.Where(ld => ld.Deleted == false &&
                                                                      ld.Owner.Id == userId &&
                                                                      ld.Video.Id == videoId)
                                     .SingleOrDefault(ld => ld.LikeOrDislike == likeDislike);

            if (exist == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#3
0
 public LikeDislikeVideo Add(LikeDislikeVideo likeDislike)
 {
     _context.Add(likeDislike);
     _context.SaveChanges();
     return(likeDislike);
 }