CrazyIter_Bin 1 年之前
父節點
當前提交
deeeee054a
共有 1 個文件被更改,包括 15 次插入2 次删除
  1. 15 2
      TEAMModelOS/Controllers/Client/AClassONEController.cs

+ 15 - 2
TEAMModelOS/Controllers/Client/AClassONEController.cs

@@ -224,7 +224,8 @@ namespace TEAMModelOS.Controllers
                             }
                         }
                         List<dynamic> stuData = new List<dynamic>();
-                        first.students.ForEach(x =>
+
+                        foreach (var x in first.students) 
                         {
                             var stu = studentes.Find(s => s.id.Equals(x.id) && s.schoolId.Equals(x.code));
                             var school = idSchools.Find(s => s.id.Equals(x.code));
@@ -246,6 +247,18 @@ namespace TEAMModelOS.Controllers
                                 teacherName = clazz?.teacher?.name;
                                 classYear = clazz?.year;
                             }
+                            if (string.IsNullOrWhiteSpace(x.relation)) {
+                                try {
+                                    Student student = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemAsync<Student>(x.id, new PartitionKey($"Base-{x.code}"));
+                                    var guardian = student.guardians.FindAll(x => x.mobile.Equals(_mobile));
+                                    if (guardian.IsNotEmpty()) {
+                                        x.relation=  guardian.First().relation;
+                                        if (!string.IsNullOrWhiteSpace(x.relation)) {
+                                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync<Guardian>(first, new PartitionKey(first.code));
+                                        }
+                                    }
+                                } catch { }
+                            }
                             stuData.Add(new
                             {
                                 x.id,
@@ -266,7 +279,7 @@ namespace TEAMModelOS.Controllers
                                 teacherName,
                                 classYear
                             });
-                        });
+                        }
                         return Ok(new { code =200,guardian = new { first.id, first.name, first.picture, first.nickname, first.mobile, students = stuData } });
                     }
                     else