Forráskód Böngészése

[API-Student]StudentManage API Create方法多回傳重複座號。(#207)

Mickey 4 éve
szülő
commit
7b4340f671
1 módosított fájl, 9 hozzáadás és 8 törlés
  1. 9 8
      TEAMModelOS/Controllers/School/StudentController.cs

+ 9 - 8
TEAMModelOS/Controllers/School/StudentController.cs

@@ -56,7 +56,7 @@ namespace TEAMModelOS.Controllers
                     case "create":
                         //創建學生->將學生加入教室->若無教室則創建教室
                         var (classInfo, classStudent, unclassStudent, existId, errorYear) = await createStudents(schoolId.GetString(), request.GetProperty("students").EnumerateArray());
-
+                        List<string> existNo = new List<string>();
                         //確認是否有教室資訊
                         if (classInfo != null && classInfo.Count != 0)
                         {
@@ -72,6 +72,7 @@ namespace TEAMModelOS.Controllers
                                     var classStudents
                                         = new Dictionary<string, List<(string id, string name, string no)>>() { { item.Key, classStudent[item.Key].Select(o => (o.id, o.name, o.no)).ToList() } };
                                     (List<string> existId, List<string> existNo) retJoinClass = await joinClass(schoolId.GetString(), classStudents);
+                                    existNo = retJoinClass.existNo;
                                 }
                                 else
                                 {
@@ -96,8 +97,7 @@ namespace TEAMModelOS.Controllers
                         {
                             ret = retUnclassStudents;
                         }
-                        if (errorYear.Count == 0) return this.Ok(new { students = ret, existId });
-                        else return this.Ok(new { students = ret, existId, errorYear });
+                        return this.Ok(new { students = ret, existId, errorYear , existNo });
                     case "read":
                         var students = await getAllStudent(schoolId.GetString());
                         return this.Ok(new { students });
@@ -934,15 +934,17 @@ namespace TEAMModelOS.Controllers
                                     string id = stud.GetProperty("id").GetString();
                                     string no = stud.GetProperty("no").GetString();
                                     string name = stud.GetProperty("name").GetString();
-                                    //string year = stud.GetProperty("year").GetString();
 
                                     tmpStuds.Add((id, name, no));
                                 }
 
                                 //先檢查ID及座號是否重複,重複的則記錄在duplicate內
-                                var duplicate = tmpStuds.Where(
-                                    a => importItem.Value.Exists(t => a.no.Contains(t.no))
-                                    || importItem.Value.Exists(t => a.id.Contains(t.id))).ToList();
+                                var duplicate = importItem.Value.Where(
+                                   i => tmpStuds.Exists(t => i.no.Contains(t.no))
+                                   || tmpStuds.Exists(t => i.id.Contains(t.id))).ToList();
+                                //var duplicate = tmpStuds.Where(
+                                //    a => importItem.Value.Exists(t => a.no.Contains(t.no))
+                                //    || importItem.Value.Exists(t => a.id.Contains(t.id))).ToList();
                                 foreach (var (id, name, no) in duplicate)
                                 {
                                     importItem.Value.RemoveAll(o => o.id.Equals(id) || o.no.Equals(no));
@@ -1366,7 +1368,6 @@ namespace TEAMModelOS.Controllers
                             writer.WriteEndArray();
                             writer.WriteEndObject();
                             writer.Flush();
-                            //var resultJson = Encoding.UTF8.GetString(memoryStream.ToArray());
 
                             try
                             {