예제 #1
0
        public async Task <IActionResult> UpvoteGame(int userId, int gameId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

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

            var upvote = await _votesRepo.GetUpvote(userId, gameId);

            var downvote = await _votesRepo.GetDownvote(userId, gameId);

            if (upvote != null)
            {
                await _votesRepo.DecreaseUpvotes(gameId);

                _boardologyRepo.Delete(upvote);
                if (await _boardologyRepo.SaveAll())
                {
                    return(Ok());
                }
                return(BadRequest("Failed to remove upvote"));
            }



            upvote = new Upvote
            {
                UpVoterId = userId,
                GameId    = gameId
            };

            _boardologyRepo.Add(upvote);

            await _votesRepo.IncreaseUpvotes(gameId);

            if (downvote != null)
            {
                await _votesRepo.DecreaseDownvotes(gameId);

                _boardologyRepo.Delete(downvote);
            }


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

            return(BadRequest("Failed to upvote game"));
        }
예제 #2
0
        public async Task <IActionResult> GetComments(int gameId)
        {
            if (await _repo.GetGame(gameId) == null)
            {
                return(NotFound());
            }

            var comments = await _repo.GetComments(gameId);

            return(Ok(comments));
        }
예제 #3
0
        public async Task <IActionResult> GetComments(int gameId, [FromQuery] CommentParams commentParams)
        {
            if (await _repo.GetGame(gameId) == null)
            {
                return(NotFound());
            }

            var comments = await _repo.GetComments(gameId, commentParams);

            Response.AddPagination(comments.CurrentPage, comments.PageSize, comments.TotalCount, comments.TotalPages);

            return(Ok(comments));
        }
예제 #4
0
        public async Task <IActionResult> UpvoteGame(int userId, int gameId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var upvote = await _repo.GetUpvote(userId, gameId);

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

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

            upvote = new Upvote
            {
                UpVoterId = userId,
                GameId    = gameId
            };

            _repo.Add(upvote);

            await _repo.IncreaseUpvotes(gameId);


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

            return(BadRequest("Failed to upvote game"));
        }
예제 #5
0
        public async Task <IActionResult> GetGame(int gameId)
        {
            var gameFromRepo = await _repo.GetGame(gameId);

            return(Ok(gameFromRepo));
        }