Example #1
0
        public async Task <IActionResult> DownvoteGame(int userId, int gameId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var downvote = await _repo.GetDownvote(userId, gameId);

            if (downvote != null)
            {
                return(BadRequest("You already downvoted this game"));
            }

            if (await _repo.GetGame(gameId) == null)
            {
                return(NotFound());
            }

            downvote = new Downvote
            {
                DownVoterId = userId,
                GameId      = gameId
            };

            _repo.Add(downvote);

            await _repo.IncreaseDownvotes(gameId);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to downvote game"));
        }
Example #2
0
        public async Task DownvoteAsync(Guid postId, Guid userId)
        {
            var post = await _postsRepository.GetByIdAsync(postId, p => p
                                                           .Include(e => e.Upvotes)
                                                           .Include(e => e.Downvotes));

            var downvote = post.Downvotes.SingleOrDefault(u => u.UserId == userId);

            if (downvote == null)
            {
                downvote = new Downvote(userId, postId);
                post.Downvotes.Add(downvote);
            }
            else
            {
                post.Downvotes.Remove(downvote);
            }

            // TODO test to see if it is necessary to use an downvotes repository
            post.UpdateRating();
            await _postsRepository.UpdateAsync(post);
        }
Example #3
0
 public async Task <BaseObject> Downvote(ActivityDeliveryContext ctx, Downvote downvote) => await ReactAndGetSummary(ctx, downvote, ReactionType.Downvote);