|
@@ -236,7 +236,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
}
|
|
|
|
|
|
|
|
|
- public async Task DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID
|
|
|
+ public async Task<List<IdPk>> DeleteAll<T>(List<KeyValuePair<string, string>> ids) where T : ID
|
|
|
{
|
|
|
Container container = await InitializeCollection<T>();
|
|
|
//string partitionKey = GetPartitionKey<T>();
|
|
@@ -245,7 +245,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
// Task.WaitAll(DeleteAsync<T>(item.Value, item.Key));
|
|
|
//}));
|
|
|
|
|
|
-
|
|
|
+ List<IdPk> idPks = new List<IdPk>();
|
|
|
int pages = (int)Math.Ceiling((double)ids.Count / pageSize);
|
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
|
for (int i = 0; i < pages; i++)
|
|
@@ -257,22 +257,30 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
tasks.Add(container.DeleteItemStreamAsync(item.Value, new PartitionKey(item.Key))
|
|
|
.ContinueWith((Task<ResponseMessage> task) =>
|
|
|
{
|
|
|
- //using (ResponseMessage response = task.Result)
|
|
|
- //{
|
|
|
- // if (!response.IsSuccessStatusCode)
|
|
|
- // {
|
|
|
- // }
|
|
|
- //}
|
|
|
+ using (ResponseMessage response = task.Result)
|
|
|
+ {
|
|
|
+ idPks.Add(new IdPk { id = item.Value, pk = item.Key.ToString(), StatusCode = response.StatusCode });
|
|
|
+ // if (!response.IsSuccessStatusCode)
|
|
|
+ // {
|
|
|
+ // }
|
|
|
+ }
|
|
|
}
|
|
|
));
|
|
|
});
|
|
|
await Task.WhenAll(tasks);
|
|
|
}
|
|
|
stopwatch.Stop();
|
|
|
+ return idPks;
|
|
|
}
|
|
|
-
|
|
|
- public async Task DeleteAll<T>(List<T> enyites) where T : ID
|
|
|
+ public async Task<List<IdPk>> DeleteAll<T>(Dictionary<string,object> dict) where T : ID
|
|
|
+ {
|
|
|
+ List<T> list= await FindByDict<T>(dict);
|
|
|
+ return await DeleteAll(list);
|
|
|
+ }
|
|
|
+ public async Task<List<IdPk>> DeleteAll<T>(List<T> enyites) where T : ID
|
|
|
{
|
|
|
+
|
|
|
+ List<IdPk> idPks = new List<IdPk>();
|
|
|
Container container = await InitializeCollection<T>();
|
|
|
string pk = GetPartitionKey<T>();
|
|
|
Type type = typeof(T);
|
|
@@ -293,36 +301,42 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
|
|
|
itemsToInsert.ForEach(item =>
|
|
|
{
|
|
|
tasks.Add(container.DeleteItemStreamAsync(item.Value, item.Key)
|
|
|
- .ContinueWith((Task<ResponseMessage> task) =>
|
|
|
+ .ContinueWith((Task<ResponseMessage> task) =>
|
|
|
{
|
|
|
- //using (ResponseMessage response = task.Result)
|
|
|
- //{
|
|
|
- // if (!response.IsSuccessStatusCode)
|
|
|
- // {
|
|
|
- // }
|
|
|
- //}
|
|
|
+ using (ResponseMessage response = task.Result)
|
|
|
+ {
|
|
|
+
|
|
|
+ idPks.Add(new IdPk { id = item.Value, pk = item.Key.ToString(), StatusCode = response.StatusCode });
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
- ));
|
|
|
+ ));
|
|
|
});
|
|
|
await Task.WhenAll(tasks);
|
|
|
}
|
|
|
stopwatch.Stop();
|
|
|
+ return idPks;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<IdPk> DeleteAsync<T>(IdPk idPk) where T : ID {
|
|
|
+ return await DeleteAsync<T>(idPk.id, idPk.pk);
|
|
|
}
|
|
|
- public async Task<T> DeleteAsync<T>(string id, string pk) where T : ID
|
|
|
+ public async Task<IdPk> DeleteAsync<T>(string id, string pk) where T : ID
|
|
|
{
|
|
|
Container container = await InitializeCollection<T>();
|
|
|
- ItemResponse<T> response = await container.DeleteItemAsync<T>(id: id, partitionKey: new PartitionKey(pk));
|
|
|
- return response.Resource;
|
|
|
+ ResponseMessage response = await container.DeleteItemStreamAsync(id: id, partitionKey: new PartitionKey(pk));
|
|
|
+
|
|
|
+ return new IdPk { id =id, pk = pk, StatusCode = response.StatusCode };
|
|
|
}
|
|
|
|
|
|
- public async Task<T> DeleteAsync<T>(T entity) where T : ID
|
|
|
+ public async Task<IdPk> DeleteAsync<T>(T entity) where T : ID
|
|
|
{
|
|
|
Container container = await InitializeCollection<T>();
|
|
|
string partitionKey = GetPartitionKey<T>();
|
|
|
Type type = typeof(T);
|
|
|
object o = type.GetProperty(partitionKey).GetValue(entity, null);
|
|
|
- ItemResponse<T> response = await container.DeleteItemAsync<T>(id: entity.id, partitionKey: new PartitionKey(o.ToString()));
|
|
|
- return response.Resource;
|
|
|
+ ResponseMessage response = await container.DeleteItemStreamAsync (id: entity.id, partitionKey: new PartitionKey(o.ToString()));
|
|
|
+ return new IdPk { id = entity.id, pk = o.ToString(), StatusCode = response.StatusCode };
|
|
|
|
|
|
}
|
|
|
//public async Task<T> DeleteAsync<T>(string id) where T : ID
|