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); }
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); }