//TODO: Renable ZoneServer authorization eventually. //[AuthorizeJwt(GuardianApplicationRole.ZoneServer)] public async Task <IActionResult> GetCharacterLocation([FromRoute(Name = "id")] int characterId, [NotNull][FromServices] ICharacterLocationRepository locationRepository) { if (locationRepository == null) { throw new ArgumentNullException(nameof(locationRepository)); } if (characterId <= 0 || !await CharacterRepository.ContainsAsync(characterId) .ConfigureAwait(false)) { return(Json(new ZoneServerCharacterLocationResponse(ZoneServerCharacterLocationResponseCode.CharacterDoesntExist))); } //So, the character exists and we now need to check if we can find a location for it. It may not have one, for whatever reason. //so we need to handle the case where it has none (maybe new character, or was manaully wiped). if (!await locationRepository.ContainsAsync(characterId).ConfigureAwait(false)) { return(Json(new ZoneServerCharacterLocationResponse(ZoneServerCharacterLocationResponseCode.NoLocationDefined))); } //Otherwise, let's load and send the result CharacterLocationModel locationModel = await locationRepository.RetrieveAsync(characterId) .ConfigureAwait(false); //TODO: Integrate Map Id design into Schema, and implement it here. return(Json(new ZoneServerCharacterLocationResponse(new Vector3(locationModel.XPosition, locationModel.YPosition, locationModel.ZPosition), 1))); }
/// <inheritdoc /> public async Task <bool> TryCreateAsync(CharacterLocationModel model) { if (await ContainsAsync(model.CharacterId)) { throw new ArgumentException($"Tried to add duplicate Key: {model.CharacterId} to character_locations", nameof(model)); } await Context .CharacterLocations .AddAsync(model); int rowChangedCount = await Context.SaveChangesAsync(); return(rowChangedCount != 0); }
/// <inheritdoc /> public Task UpdateAsync(int key, CharacterLocationModel model) { GeneralGenericCrudRepositoryProvider <int, CharacterLocationModel> crudProvider = new GeneralGenericCrudRepositoryProvider <int, CharacterLocationModel>(Context.CharacterLocations, Context); return(crudProvider.UpdateAsync(key, model)); }