示例#1
0
        public async Task <LikeVideoDetail> FindFavorite(LikeVideoRequest request)
        {
            var like = _context.LikeVideoDetail.FirstOrDefault(x => x.UserId == request.UserId &&
                                                               x.VideoId == request.VideoId && x.Reaction == "Like");

            return(like);
        }
        public async Task <int> Create(LikeVideoRequest likeRequest)
        {
            var like = new LikeVideoDetail();

            if (likeRequest != null)
            {
                like.Reaction = likeRequest.Reaction;
                like.UserId   = likeRequest.UserId;
                like.VideoId  = likeRequest.VideoId;
            }
            _context.LikeVideoDetail.Add(like);
            return(await _context.SaveChangesAsync());
        }
        public async Task <int> Update(LikeVideoRequest likeRequest)
        {
            var like = _context.LikeVideoDetail.FirstOrDefault(X => X.Id == likeRequest.Id);

            if (likeRequest != null)
            {
                like.Reaction = likeRequest.Reaction;
                like.UserId   = likeRequest.UserId;
                like.VideoId  = likeRequest.VideoId;
            }
            _context.Update(like);
            return(await _context.SaveChangesAsync());
        }
示例#4
0
        public async Task <IActionResult> DeleteFavorite(LikeVideoRequest resquest)
        {
            if (resquest != null)
            {
                var Like = await _videoWatched.FindFavorite(resquest);

                var result = await _videoWatched.DeleteFavorite(Like.Id);

                if (result > 0)
                {
                    return(Content("Success"));
                }
            }
            return(Content("Error"));
        }