예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
 public async Task Delete(OnboardingState state)
 {
     var entity          = ToEntity(state);
     var deleteOperation = TableOperation.Delete(entity);
     await table.ExecuteAsync(deleteOperation);
 }
예제 #5
0
 private static OnboardingState ToModel(DynamicTableEntity entity)
 {
     return(OnboardingState.Create(entity));
 }