コード例 #1
0
        public async Task HandleAsync(AcceptFriendshipInvitationCommand command)
        {
            var invitation = await _invitationRepository.GetAsync(new InvitationId(command.InvitationId)) ?? throw new FriendshipInvitationNotFound();

            if (await _friendshipRepository.ExistsBetweenAsync(invitation.SenderId, invitation.ReceiverId))
            {
                throw new InvalidInvitationException();
            }

            var friendship = invitation.AcceptInvitation(new PersonId(command.ReceiverId), _clock);

            await _friendshipRepository.AddAsync(friendship);
        }
コード例 #2
0
        public async Task CreateFriendshipAsync(Guid characterId, IEnumerable <Guid> friends)
        {
            var dbCharacter = await _characterRepository.GetAsync(characterId);

            if (dbCharacter == null)
            {
                throw new Exception("");
            }
            foreach (var friendId in friends)
            {
                var friend = await _characterRepository.GetAsync(friendId);

                if (friend == null)
                {
                    continue;
                }
                var friendship = await _friendshipFactory.CreateAsync(dbCharacter.Id, friendId);

                await _friendshipRepository.AddAsync(friendship);
            }
        }