public async Task <CharacterModuleResponse> Handle(UpdateCharacterCommand request, CancellationToken cancellationToken) { var character = await _repository.Get(request.Id); if (character == null) { return(CharacterModuleResponse.NotFound); } if (character.Name != request.Name && await _repository.IsNameTaken(request.Name)) { return(CharacterModuleResponse.Duplicate); } if (request.FriendsIds.Contains(character.Id)) { return(CharacterModuleResponse.SelfFriend); } var friends = await _repository.GetRange(request.FriendsIds); var friendships = friends.Select(x => new Friendship(character, x)).ToList(); character.ChangeName(request.Name); character.ChangeEpisodes(request.Episodes); character.ChangeFriends(friendships); await _repository.Update(character); return(CharacterModuleResponse.Success); }
public async Task <CharacterModuleResponse> Handle(DeleteCharacterCommand request, CancellationToken cancellationToken) { var character = await _repository.Get(request.Id); if (character == null) { return(CharacterModuleResponse.NotFound); } await _repository.Delete(character); return(CharacterModuleResponse.Success); }