Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
 private static CharacterLocationModel BuildCharacterLocationFromSave(int characterId, ZoneServerCharacterLocationSaveRequest saveRequest)
 {
     return(new CharacterLocationModel(characterId, saveRequest.Position.x, saveRequest.Position.y, saveRequest.Position.z, saveRequest.MapId));
 }
Exemplo n.º 3
0
 /// <inheritdoc />
 public async Task SaveCharacterLocation(ZoneServerCharacterLocationSaveRequest saveRequest)
 {
     await(await GetService().ConfigureAwait(false)).SaveCharacterLocation(saveRequest).ConfigureAwait(false);
 }