public async Task SendGameInvite(GameInvite inviteRequest)
        {
            if (inviteRequest.hostId == inviteRequest.invitedId)
            {
                throw new SendToYourselfException();
            }

            Player player = await _playerRepository.GetByUsername(inviteRequest.invitedId);

            if (player == null)
            {
                throw new EntityNotFoundException();
            }

            PlayerFriend foundFriend = new PlayerFriend(inviteRequest.hostId, inviteRequest.invitedId);

            foundFriend = await _friendListRepository.GetByUsernames(foundFriend.playerId, foundFriend.friendId);

            if (foundFriend == null)
            {
                throw new FriendNotFoundException();
            }

            GameInvite foundInvite = await _gameInviteRepository.GetByRoomAndInvited(inviteRequest.invitedId, inviteRequest.roomId);

            if (foundInvite != null)
            {
                throw new AlreadyExistsGameInvite();
            }
            await _gameInviteRepository.Create(inviteRequest);
        }
示例#2
0
        public async Task SendFriendInvite(string playerId, string targetPlayerId)
        {
            if (playerId == targetPlayerId)
            {
                throw new SendToYourselfException();
            }

            Player player = await _playerRepository.GetByUsername(targetPlayerId);

            if (player == null)
            {
                throw new EntityNotFoundException();
            }

            PlayerFriend foundFriend = new PlayerFriend(playerId, targetPlayerId);

            foundFriend = await _friendListRepository.GetByUsernames(foundFriend.playerId, foundFriend.friendId);

            if (foundFriend != null)
            {
                throw new AlreadyFriendsException();
            }
            FriendInvite foundSendRequest = await _requestsRepository.GetByUsernames(playerId, targetPlayerId);

            FriendInvite foundReceiveRequest = await _requestsRepository.GetByUsernames(targetPlayerId, playerId);

            if (foundSendRequest != null || foundReceiveRequest != null)
            {
                throw new AlreadyExistsFriendRequest();
            }

            FriendInvite createRequest = new FriendInvite();

            createRequest.playerId       = playerId;
            createRequest.targetPlayerId = targetPlayerId;
            await _requestsRepository.Create(createRequest);
        }