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 Delete(PlayerFriend friendship) { var remove = await GetByUsernames(friendship.playerId, friendship.friendId); if (remove != null) { _context.FriendsList.Remove(remove); } await _context.SaveChangesAsync(); }
public async Task UnfriendPlayer(string playerId, string targetPlayerId) { 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 FriendNotFoundException(); } await _friendListRepository.Delete(foundFriend); }
public async Task AcceptFriendInvite(FriendInvite sendRequest, bool accept) { Player player = await _playerRepository.GetByUsername(sendRequest.targetPlayerId); if (player == null) { throw new EntityNotFoundException(); } FriendInvite request = await _requestsRepository.GetByUsernames(sendRequest.playerId, sendRequest.targetPlayerId); if (request == null) { throw new FriendRequestNotFound(); } if (accept) { PlayerFriend friend = new PlayerFriend(sendRequest.playerId, sendRequest.targetPlayerId); await _friendListRepository.Create(friend); } await _requestsRepository.Delete(sendRequest); }
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); }
public async Task Create(PlayerFriend friend) { _context.FriendsList.Add(friend); await _context.SaveChangesAsync(); }