public async Task <IActionResult> UpdateCharacterLocation( [FromBody] ZoneServerCharacterLocationSaveRequest saveRequest, [NotNull][FromServices] ICharacterLocationRepository locationRepository) { if (locationRepository == null) { throw new ArgumentNullException(nameof(locationRepository)); } int characterId = saveRequest.CharacterId; if (characterId <= 0 || !await CharacterRepository.ContainsAsync(characterId) .ConfigureAwait(false)) { return(NotFound()); } //TODO: Is this the best way to deal with this? if (await locationRepository.ContainsAsync(characterId).ConfigureAwait(false)) { await locationRepository.UpdateAsync(characterId, BuildCharacterLocationFromSave(characterId, saveRequest)) .ConfigureAwait(false); } else { await locationRepository.TryCreateAsync(BuildCharacterLocationFromSave(characterId, saveRequest)) .ConfigureAwait(false); } return(Ok()); }
private static CharacterLocationModel BuildCharacterLocationFromSave(int characterId, ZoneServerCharacterLocationSaveRequest saveRequest) { return(new CharacterLocationModel(characterId, saveRequest.Position.x, saveRequest.Position.y, saveRequest.Position.z, saveRequest.MapId)); }
/// <inheritdoc /> public async Task SaveCharacterLocation(ZoneServerCharacterLocationSaveRequest saveRequest) { await(await GetService().ConfigureAwait(false)).SaveCharacterLocation(saveRequest).ConfigureAwait(false); }