Parcourir la source

[BI]移除教師後訊息未刪除API修正

jeff il y a 2 ans
Parent
commit
8fe7535637
1 fichiers modifiés avec 14 ajouts et 1 suppressions
  1. 14 1
      TEAMModelBI/Controllers/BISchool/SchoolController.cs

+ 14 - 1
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -854,13 +854,26 @@ namespace TEAMModelBI.Controllers.BISchool
             //    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
             //    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
             List<string> existScId = new();
             List<string> existScId = new();
             StringBuilder strMsg = new($"{_tmdName}【{_tmdId}】管理员账户将{tmdId}的账户移除学校:");
             StringBuilder strMsg = new($"{_tmdName}【{_tmdId}】管理员账户将{tmdId}的账户移除学校:");
+            //老師
+            if (rmvFromSc) //從老師的學校列表移除該學校
+            {
+                var response = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{tmdId}", new PartitionKey("Base"));
+                if (response.Status == 200)
+                {
+                    using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                    Teacher teacher = json.ToObject<Teacher>();
+                    teacher.schools.RemoveAll(s => scIds.Contains(s.schoolId));
+                    await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
+                }
+            }
+            //學校
             SchoolTeacher scTeacher = null;
             SchoolTeacher scTeacher = null;
             foreach (var scId in scIds)
             foreach (var scId in scIds)
             {
             {
                 var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{scId}"));
                 var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{scId}"));
                 if (response.Status == 200)
                 if (response.Status == 200)
                 {
                 {
-                    if (rmvFromSc)
+                    if (rmvFromSc) //將該老師從學校的老師名單中移除
                     {
                     {
                         await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>($"{tmdId}", new PartitionKey($"Teacher-{scId}"));
                         await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>($"{tmdId}", new PartitionKey($"Teacher-{scId}"));
                     }
                     }