public async Task <User> Upsert(Guid appId, User user) { var userEntity = await GetUser(user.Email); if (userEntity == null) { userEntity = new UserEntity { PartitionKey = GlobalPartitionKey, RowKey = GetUserRowKey(user.Email), }; var userResult = await _table.ExecuteAsync(TableOperation.InsertOrReplace(userEntity)); userEntity = (UserEntity)userResult.Result; } var userMetadataEntity = new UserMetadataEntity { PartitionKey = appId.ToString(), RowKey = userEntity.RowKey, CustomData = JsonConvert.SerializeObject(user.CustomData) }; var result = await _table.ExecuteAsync(TableOperation.InsertOrReplace(userMetadataEntity)); userMetadataEntity = (UserMetadataEntity)result.Result; return(ToDto(userMetadataEntity)); }
public async Task <User> Upsert(Guid appId, User user) { var userEntity = await GetUser(user.Email); if (userEntity == null) { userEntity = new UserEntity { PartitionKey = GlobalPartitionKey, RowKey = GetUserRowKey(user.Email), }; var userResult = await _table.ExecuteAsync(TableOperation.InsertOrReplace(userEntity)); userEntity = (UserEntity)userResult.Result; } var userMetadataEntity = new UserMetadataEntity { PartitionKey = appId.ToString(), RowKey = userEntity.RowKey, CustomData = user.CustomData }; var result = await _table.ExecuteAsync(TableOperation.InsertOrReplace(userMetadataEntity)); userMetadataEntity = (UserMetadataEntity)result.Result; return(new User { Email = userEntity.RowKey.Substring(UserRowKeyPrefix.Length), CustomData = userMetadataEntity.CustomData }); }
private static User ToDto(UserMetadataEntity metadataEntity) => new User { Email = metadataEntity.RowKey.Split(';').Last(), CustomData = JsonConvert.DeserializeObject <JObject>(metadataEntity.CustomData) };