Пример #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> DeleteFromCollection(int userId, int gameId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var collectionItem = await _collectionRepo.GetCollectionItem(userId, gameId);

            if (collectionItem == null)
            {
                return(NotFound());
            }


            if (collectionItem.UserId != userId)
            {
                return(Unauthorized());
            }

            _boardologyRepo.Delete(collectionItem);

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

            return(BadRequest("Failed to delete game from collection"));
        }
Пример #3
0
        public async Task <IActionResult> DeleteComment(int userId, int gameId, int commentId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var comment = await _repo.GetComment(commentId);

            if (comment == null)
            {
                return(NotFound());
            }

            if (comment.UserId != userId)
            {
                return(Unauthorized());
            }

            _repo.Delete(comment);
            await _commentsRepo.DecreaseComments(gameId);


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

            return(BadRequest("Failed to delete comment"));
        }
Пример #4
0
        public async Task <IActionResult> DeleteGame(int gameId)
        {
            var gameFromRepo = await _repo.GetGame(gameId);

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

            _repo.Delete(gameFromRepo);

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

            return(BadRequest("Failed to delete game"));
        }