public async Task <FriendDto> Accept(Guid inviteId, Guid userId) { var friend = await _repository.GetSingle(inviteId); if (friend.FriendUserId.Equals(userId)) { friend.Accept(); if (await _repository.Update(friend)) { // Also make the other users friends... var reverseFriends = await _repository.FindByUsers(friend.FriendUserId, friend.UserGuid); if (reverseFriends == null) { reverseFriends = Friend.Create(friend.FriendUserId, friend.UserGuid); } reverseFriends.Accept(); if (await _repository.Create(reverseFriends)) { var friendUser = await _usersRepository.Get(friend.FriendUserId); var currentUser = await _usersRepository.Get(friend.UserGuid); // Signal the originator a friend request was accepted PublishFriendInvitationAcceptedEvent(friend.FriendUserId, friend.UserGuid, currentUser?.Name); // Signal the receiver user they became friends.. PublishFriendInvitationAcceptedEvent(friend.UserGuid, friend.FriendUserId, friendUser?.Name); } return(friend.ToDto()); } } return(null); }