private static DynamicTableEntity ToEntity(OnboardingState model) { var properties = TableEntity.Flatten(model, null); var entity = new DynamicTableEntity( GetPartitionKey(model.Id), GetRowKey(model.Id), model.ETag, properties); return(entity); }
public async Task <OnboardingState> Update(OnboardingState state) { var entity = ToEntity(state); var updateOperation = TableOperation.Replace(entity); var result = await table.ExecuteAsync(updateOperation); var updatedEntity = (DynamicTableEntity)result.Result; return(ToModel(updatedEntity)); }
public async Task <OnboardingState> GetOrCreate(string email, string botSessionId) { var query = new TableQuery() .Where(TableQuery.GenerateFilterCondition(nameof(OnboardingState.UserEmail), QueryComparisons.Equal, email)); var result = await table.ExecuteQuerySegmentedAsync(query, null); var existingEntity = result.SingleOrDefault(); if (existingEntity != null) { return(ToModel(existingEntity)); } var model = new OnboardingState(email, botSessionId); var entity = ToEntity(model); var insertOperation = TableOperation.Insert(entity); var insertResult = await table.ExecuteAsync(insertOperation); entity = (DynamicTableEntity)insertResult.Result; return(ToModel(entity)); }
public async Task Delete(OnboardingState state) { var entity = ToEntity(state); var deleteOperation = TableOperation.Delete(entity); await table.ExecuteAsync(deleteOperation); }
private static OnboardingState ToModel(DynamicTableEntity entity) { return(OnboardingState.Create(entity)); }