Browse Source

更改学生year数据类型

CrazyIter_Bin 4 years ago
parent
commit
fd0a0a96ef

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Student/Student.cs

@@ -15,7 +15,7 @@ namespace TEAMModelOS.SDK.Models
         public string schoolId { get; set; }
         public string pw { get; set; }
         public string salt { get; set; }
-        public string year { get; set; }
+        public int year { get; set; }
         //座位号
         public string no { get; set; }
         //绑定班级Id

+ 11 - 11
TEAMModelOS/Controllers/School/StudentController.cs

@@ -69,14 +69,14 @@ namespace TEAMModelOS.Controllers
                         while (importStuds.MoveNext())
                         {
                             JsonElement currStud = importStuds.Current;
-                            string id = null, name = null, pw = null, year = null, no = null, classId = null;
-
+                            string id = null, name = null, pw = null,  no = null, classId = null;
+                            int year = 0;
                             //讀取輸入的資料
                             if (!currStud.TryGetProperty("id", out var tmpId) || !currStud.TryGetProperty("name", out var tmpName)) continue;
                             id = tmpId.GetString();
                             name = tmpName.GetString();
                             if (currStud.TryGetProperty("pw", out var tmpPw)) pw = tmpPw.GetString();
-                            if (currStud.TryGetProperty("year", out var tmpYear)) year = tmpYear.GetString();
+                            if (currStud.TryGetProperty("year", out var tmpYear)) year = tmpYear.GetInt32();
                             if (currStud.TryGetProperty("no", out var tmpNo)) no = tmpNo.GetString();
                             if (currStud.TryGetProperty("classId", out var tmpClassId)) classId = tmpClassId.GetString();
 
@@ -537,7 +537,7 @@ namespace TEAMModelOS.Controllers
                 if (string.IsNullOrWhiteSpace(studCreateInfo.gender)) writer.WriteNull("gender");
                 else writer.WriteString("gender", studCreateInfo.gender);
                 writer.WriteString("schoolId", schoolId);
-                writer.WriteString("year", studCreateInfo.year);
+                writer.WriteNumber("year", studCreateInfo.year);
                 writer.WriteNull("picture");
                 writer.WriteNull("mail");
                 writer.WriteNull("mobile");
@@ -804,7 +804,7 @@ namespace TEAMModelOS.Controllers
             {   
                 //TODO : 進階查詢選項調整、部分地方可用並行處理
                 //以學校學生角度去抓資料
-                Dictionary<string, List<(string id, string name, string pic, string year, string no)>> dicClassStuds = new Dictionary<string, List<(string id, string name, string pic, string year, string no)>>();
+                Dictionary<string, List<(string id, string name, string pic, int year, string no)>> dicClassStuds = new Dictionary<string, List<(string id, string name, string pic, int year, string no)>>();
                 List<(string id, string name, string pic, string year, string no)> notJoinClassStuds = new List<(string id, string name, string pic, string year, string no)>();
                 
                 string queryText = $"SELECT c.id, c.name, c.picture, c.year, c.classId, c.no FROM c WHERE c.code = 'Base-{schoolId}'";
@@ -824,7 +824,7 @@ namespace TEAMModelOS.Controllers
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
                     if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                     {
-                        List<(string id, string name, string pic, string year,string no)> students = new List<(string id, string name, string pic, string year, string no)>();
+                        List<(string id, string name, string pic, int year,string no)> students = new List<(string id, string name, string pic, int year, string no)>();
 
                         var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
                         while (accounts.MoveNext())
@@ -852,7 +852,7 @@ namespace TEAMModelOS.Controllers
                                             acc.GetProperty("id").GetString(), 
                                             acc.GetProperty("name").GetString(),
                                             acc.GetProperty("picture").GetString(),
-                                            acc.GetProperty("year").GetString(),
+                                            acc.GetProperty("year").GetInt32(),
                                             acc.GetProperty("no").GetString()
                                         )
                                     );
@@ -860,13 +860,13 @@ namespace TEAMModelOS.Controllers
                             else
                             {
                                 dicClassStuds.Add(classId, 
-                                        new List<(string id, string name, string pic, string year, string no)>() 
+                                        new List<(string id, string name, string pic, int year, string no)>() 
                                         {
                                             (
                                                 acc.GetProperty("id").GetString(),
                                                 acc.GetProperty("name").GetString(),
                                                 acc.GetProperty("picture").GetString(),
-                                                acc.GetProperty("year").GetString(),
+                                                acc.GetProperty("year").GetInt32(),
                                                 acc.GetProperty("no").GetString()
                                             )
                                         }
@@ -1707,7 +1707,7 @@ namespace TEAMModelOS.Controllers
 
         private struct studCreateInfo
         {
-            public studCreateInfo(string id, string name, string gender, string year, string pw, string classId, string no)
+            public studCreateInfo(string id, string name, string gender, int year, string pw, string classId, string no)
             {
                 this.id = id;
                 this.name = name;
@@ -1720,7 +1720,7 @@ namespace TEAMModelOS.Controllers
             public string id { get; }
             public string name { get; }
             public string gender { get; }
-            public string year { get; }
+            public int year { get; }
             public string pw { get; }
             public string classId { get; }
             public string no { get; }