private async Task UpdateConfigEntryAsync(GameConfigurationUpdateRequest <TConfigType> request, int ownershipId, CancellationToken token = default) { if (request == null) { throw new ArgumentNullException(nameof(request)); } switch (request.Source) { case ConfigurationSourceType.Account: { var entry = await AccountConfigRepository.RetrieveAsync(new GameConfigurationKey <TConfigType>(ownershipId, request.ConfigType), token); entry.Data = new GameConfigData(request.Data); await AccountConfigRepository.UpdateAsync(new GameConfigurationKey <TConfigType>(ownershipId, request.ConfigType), entry, token); return; } case ConfigurationSourceType.Character: { var entry = await CharacterConfigRepository.RetrieveAsync(new GameConfigurationKey <TConfigType>(ownershipId, request.ConfigType), token); entry.Data = new GameConfigData(request.Data); await CharacterConfigRepository.UpdateAsync(new GameConfigurationKey <TConfigType>(ownershipId, request.ConfigType), entry, token); return; } default: throw new ArgumentOutOfRangeException(nameof(request.Source), request.Source, null); } }
public async Task UpdateGameConfigAsync([FromBody] GameConfigurationUpdateRequest <TConfigType> request, CancellationToken token = default) { int ownershipId = RetrieveOwnershipId(request.Source); if (!await ContainsConfigEntryAsync(request.Source, request.ConfigType, ownershipId, token)) { if (!await CreateConfigEntryAsync(request, ownershipId, token)) { throw new InvalidOperationException($"Failed to create Config for Source: {request.Source} Id: {ownershipId}"); } } await UpdateConfigEntryAsync(request, ownershipId, token); }
private async Task <bool> CreateConfigEntryAsync(GameConfigurationUpdateRequest <TConfigType> request, int ownershipId, CancellationToken token = default) { if (request == null) { throw new ArgumentNullException(nameof(request)); } switch (request.Source) { case ConfigurationSourceType.Account: return(await AccountConfigRepository.TryCreateAsync(new AccountGameConfiguration <TConfigType>(ownershipId, new GameConfigData(request.Data), request.ConfigType), token)); case ConfigurationSourceType.Character: return(await CharacterConfigRepository.TryCreateAsync(new CharacterGameConfiguration <TConfigType>(ownershipId, new GameConfigData(request.Data), request.ConfigType), token)); default: throw new ArgumentOutOfRangeException(nameof(request.Source), request.Source, null); } }