public async Task <CharacterLocationDto> Handle(SpawnCharacterCommand request, CancellationToken cancellationToken) { var random = new Random(SystemClock.Now.Millisecond); var characterLocation = CharacterLocation.Create(request.CharacterId, random.Next(-2, 2), random.Next(-2, 2), _singleLocationPerCharacterChecker); await _characterLocationRepository.AddAsync(characterLocation, cancellationToken); await _unitOfWork.CommitAsync(cancellationToken); return(CharacterLocationDto.FromCharacterLocation(characterLocation)); }
public async Task <CharacterLocationDto> Handle(MoveCharacterCommand request, CancellationToken cancellationToken) { var characterLocation = await _characterLocationRepository.GetByCharacterIdAsync(request.CharacterId, cancellationToken); if (characterLocation != null) { characterLocation.ChangeLocation(request.X, request.Y); } else { characterLocation = CharacterLocation.Create(request.CharacterId, request.X, request.Y, _singleLocationPerCharacterChecker); await _characterLocationRepository.AddAsync(characterLocation, cancellationToken); } await _unitOfWork.CommitAsync(cancellationToken); return(CharacterLocationDto.FromCharacterLocation(characterLocation)); }