public void CommentDislike(string userId, int commentId,
                                   string likeSpan, string dislikeSpan)
        {
            Dislikes dislike = repository.Dislikes
                               .FirstOrDefault(d => d.For == "Comment" && d.ForId == commentId &&
                                               d.UserId == userId);

            if (dislike == null)
            {
                dislike = new Dislikes
                {
                    For    = "Comment",
                    ForId  = commentId,
                    UserId = userId
                };
                repository.AddDislike(dislike);

                //notification
                _ = ShowNotification(userId, commentId);
            }
            else
            {
                repository.DeleteDislike(dislike.Id);
            }

            _ = CommentLikesDislikesInitial(userId, commentId, likeSpan, dislikeSpan);
        }
        public ActionResult RemoveDislike(string userId, string For, int forId, string spanId)
        {
            ViewData["Id"] = userId;

            Dislikes dislike = repository.Dislikes
                               .FirstOrDefault(d => d.For == For && d.ForId == forId && d.UserId == userId);

            repository.DeleteDislike(dislike.Id);

            return(PartialView("LikesDislikesCount", new LikesDislikes
            {
                For = For,
                ForId = forId,
                spanId = spanId,
                Likes = repository.Likes.Where(l => l.For == For && l.ForId == forId),
                Dislikes = repository.Dislikes.Where(d => d.For == For && d.ForId == forId)
            }));
        }
Ejemplo n.º 3
0
        public async Task VideoDislikes(int videoId, string userId)
        {
            bool     likeInd    = false;
            bool     dislikeInd = false;
            Dislikes dislike    = repository.Dislikes
                                  .FirstOrDefault(d => d.For == "Video" &&
                                                  d.ForId == videoId && d.UserId == userId);

            if (dislike == null)
            {
                dislike = new Dislikes
                {
                    For    = "Video",
                    ForId  = videoId,
                    UserId = userId
                };
                repository.AddDislike(dislike);
                dislikeInd = true;

                _ = ShowNotification(userId, videoId);
            }
            else
            {
                repository.DeleteDislike(dislike.Id);
            }

            int totalLikes = repository.Likes
                             .Where(l => l.For == "Video" && l.ForId == videoId)
                             .Count();
            int totalDislikes = repository.Dislikes
                                .Where(d => d.For == "Video" && d.ForId == videoId)
                                .Count();

            await Clients.All.SendAsync("AddRemoveDislike", videoId, userId,
                                        totalLikes, likeInd, totalDislikes, dislikeInd);
        }