public async Task <ResponseModel> DeletePartition(EntityTableType table, string partitionKey) { try { var t = await GetTable(KEY, table.ToString()); TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition(EntityBase.PARTITION_KEY, QueryComparisons.Equal, partitionKey)); query.SelectColumns = new List <string> { "Timestamp" }; var rs = (await t.ExecuteQuerySegmentedAsync(query, null)); if (rs.Count() > 0) { TableBatchOperation batch = new TableBatchOperation(); foreach (var item in rs) { batch.Add(TableOperation.Delete(item)); } await t.ExecuteBatchAsync(batch); return(ResponseModel.Success()); } return(ResponseModel.Success()); } catch (StorageException ex) { return(ResponseModel.Error(ex)); } catch (Exception ex) { return(ResponseModel.Error(ex)); } }
public async Task <ResponseModel> BatchOperations(EntityTableType table, TableBatchOperation batch) { try { var t = await GetTable(KEY, table.ToString()); var rs = await t.ExecuteBatchAsync(batch); var errs = rs.Where(c => c.HttpStatusCode < 200 || c.HttpStatusCode > 299); if (errs.Count() > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendLine("For Table: " + table.ToString()); foreach (var err in errs) { sb.AppendLine(JsonConvert.SerializeObject(err.Result)); } return(ResponseModel.Error(ResponseCode.Internal_DatabaseError, sb.ToString())); } } catch (StorageException ex) { if (ex.RequestInformation.HttpStatusCode == 412) { return(ResponseModel.Error(ResponseCode.StoragePreconditionFailed, ex.Message)); } return(ResponseModel.Error(ex)); } catch (Exception ex) { return(ResponseModel.Error(ex)); } return(ResponseModel.Success()); }
public async Task <ResponseModel <DynamicTableEntity> > QueryEntities(EntityTableType type, TableQuery query) { try { var t = await GetTable(KEY, type.ToString()); var rs = (await t.ExecuteQuerySegmentedAsync(query, null)); return(rs.Count() > 0 ? ResponseModel <DynamicTableEntity> .Success(rs.ToList()) : ResponseModel <DynamicTableEntity> .Error(ResponseCode.NoData)); } catch (StorageException ex) { return(ResponseModel <DynamicTableEntity> .Error(ex)); } catch (Exception ex) { return(ResponseModel <DynamicTableEntity> .Error(ex)); } }
public async Task <ResponseModel> UpdateEntityProperty(EntityTableType table, DynamicTableEntity entity) { try { var t = await GetTable(KEY, table.ToString()); var rs = (await t.ExecuteAsync(TableOperation.Merge(entity))); return(rs.HttpStatusCode >= 200 && rs.HttpStatusCode < 300 ? ResponseModel.Success() : ResponseModel.Error(rs.HttpStatusCode)); } catch (StorageException ex) { return(ResponseModel.Error(ex)); } catch (Exception ex) { return(ResponseModel.Error(ex)); } }
public async Task <ResponseModel> DeleteEntity(EntityTableType type, string partitionKey, string rowKey) { try { var t = await GetTable(KEY, type.ToString()); var te = new TableEntity(partitionKey, rowKey); var rs = (await t.ExecuteAsync(TableOperation.Delete(te))); return(rs.HttpStatusCode >= 200 && rs.HttpStatusCode < 300 ? ResponseModel.Success() : ResponseModel.Error(rs.HttpStatusCode)); } catch (StorageException ex) { return(ResponseModel.Error(ex)); } catch (Exception ex) { return(ResponseModel.Error(ex)); } }