CrazyIter_Bin 3 years ago
parent
commit
6aa62c7d90
1 changed files with 19 additions and 1 deletions
  1. 19 1
      TEAMModelFunction/ScsApisHttpTrigger.cs

+ 19 - 1
TEAMModelFunction/ScsApisHttpTrigger.cs

@@ -21,6 +21,8 @@ using TEAMModelOS.SDK.Models.Service;
 using HTEXLib.COMM.Helpers;
 using HTEXLib.COMM.Helpers;
 using System.Text;
 using System.Text;
 using static TEAMModelOS.SDK.Models.Teacher;
 using static TEAMModelOS.SDK.Models.Teacher;
+using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
+using Azure.Storage.Blobs.Models;
 
 
 namespace TEAMModelFunction
 namespace TEAMModelFunction
 {
 {
@@ -52,7 +54,7 @@ namespace TEAMModelFunction
         [FunctionName("knowledge-change")]
         [FunctionName("knowledge-change")]
         public async Task<IActionResult> KnowledgeChange([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) {
         public async Task<IActionResult> KnowledgeChange([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) {
             string data = await new StreamReader(req.Body).ReadToEndAsync();
             string data = await new StreamReader(req.Body).ReadToEndAsync();
-           var  json = JsonDocument.Parse(data).RootElement;
+            var  json = JsonDocument.Parse(data).RootElement;
             List<OldNew> old_new = null;
             List<OldNew> old_new = null;
             string school = null;
             string school = null;
             if (json.TryGetProperty("school", out JsonElement _school))
             if (json.TryGetProperty("school", out JsonElement _school))
@@ -95,6 +97,22 @@ namespace TEAMModelFunction
                     });
                     });
                     foreach (var item in items)
                     foreach (var item in items)
                     {
                     {
+                        ItemBlob itemBlob = null;
+                        try
+                        {
+                            BlobDownloadInfo blobDownloadResult = await _azureStorage.GetBlobContainerClient($"hbcn").GetBlobClient($"/item/{item.id}/{item.id}.json").DownloadAsync();
+                            if (blobDownloadResult != null)
+                            {
+                                var blob = JsonDocument.Parse(blobDownloadResult.Content);
+                                itemBlob = blob.RootElement.ToObject<ItemBlob>();
+                                itemBlob.exercise.knowledge = item.knowledge;
+                                await _azureStorage.UploadFileByContainer("hbcn", itemBlob.ToJsonString(), "item", $"{item.id}/{item.id}.json", true);
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            itemBlob = null;
+                        }
                         await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
                         await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
                     }
                     }
                 }
                 }