Example #1
0
        public async Task AddFriendToCharacterAsync(Character character, Character friend)
        {
            if (_characterRepository.HasFriendAlready(character, friend))
            {
                throw new InvalidOperationException($"{friend?.Name} is already friend of {character.Name}");
            }

            if (character.Id == friend.Id)
            {
                throw new InvalidOperationException($"Cannot add friend of myself");
            }

            _characterRepository.AddFriendToCharacter(character, friend);
            await _characterRepository.SaveChangesAsync();
        }